
: 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
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?
More posts by @Sarah324
1 Comments
Sorted by latest first Latest Oldest Best
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/(.+))$
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.