我正在尝试为以下情况找到正确的mod_rewrite代码:
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/...
所以基本上
有人能想到一个聪明的解决方案吗?我一直在努力使用{REQUEST_URI}和{REQUEST_FILENAME}试图弄清楚请求的URI是否以.de或.de /结尾但无法找到可行的解决方案......
答案 0 :(得分:1)
试试这个:
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]
答案 1 :(得分:0)
点击此处查看一些示例: http://www.thesitewizard.com/apache/redirect-domain-www-subdomain.shtml
在这里: http://howto.kryl.info/mod_rewrite/
开始:
RewriteCond%{HTTP_HOST} ^ domain.de $ [NC]
RewriteRule ^(。*)$ http://www.domain.com/de/ $ 1 [R = 301,L]
等