mod_rewrite on domain root
I am trying to find the correct mod_rewrite code for the following case:
domain.de => www.domain.com/de/
domain.de/... => www.domain.com/...
www.domain.de => www.domain.com/de/
www.domain.de/... => www.domain.com/...
domain.com => www.domain.com/en/
domain.com/... => www.domain.com/...
www.domain.com => www.domain.com/en/
www.domain.com/... => www.domain.com/...
so basically
- all non-www domains should be redirect to www.
- all uri's ending on .de or .de/ should be redirected to www.domain.com/de/
- but if somebody enters something after the .de/ that should be simply开发者_运维问答 appended to www.domain.com/...
Can anyone think of a clever solution for this? I have been struggling with {REQUEST_URI} and {REQUEST_FILENAME} trying to figure out if the requested URI ends on .de or .de/ but couldn't find a working solution...
Try this:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.de$
RewriteRule ^$ http://www.example.com/de/ [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.de$
RewriteRule . http://www.example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^$ http://www.example.com/en/ [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule . http://www.example.com%{REQUEST_URI} [L,R=301]
Check some examples here: http://www.thesitewizard.com/apache/redirect-domain-www-subdomain.shtml
and here: http://howto.kryl.info/mod_rewrite/
to start:
RewriteCond %{HTTP_HOST} ^domain.de$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/de/$1 [R=301,L]
etc
精彩评论