开发者

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

  1. all non-www domains should be redirect to www.
  2. all uri's ending on .de or .de/ should be redirected to www.domain.com/de/
  3. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜