Mobile app version of vmapp.org
Login or Join
Sarah324

: Redirect a subdirectory to the main domain in htaccess I have the folowing structure: www.example.com - DE version www.example.com/de - DE version www.example.com/en - EN version I want to be

@Sarah324

Posted in: #Htaccess #ModRewrite

I have the folowing structure:
example.com - DE version example.com/de - DE version example.com/en - EN version


I want to be like that:
example.com - DE version example.com/de ---> Redirect 301 to site.com www.example.com/en - EN version


That's my current htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ www.%{HTTP_HOST}/ [R=301,L]


I have tried examples but no success.
Any ideas?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sarah324

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

To redirect example.com/de to example.com (and all the URLs within) then you can do something like the following (after your current directives):

RewriteRule ^(?:de|de/(.*))$ / [R=301,L]


This will redirect /de or /de/ or /de/something to the corresponding URL in the document root. It won't redirect /desomething (in case you have other files in the root that start "de").

The ?: after the first parenthesis makes the group non-capturing.

To prevent /de/ (trailing slash) from redirecting you could change the * (0 or more) to + (1 or more) in the regex. ie. ^(?:de|de/(.+))$

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme