0

如何在以下条件下设置重定向:

网址http://domainname.be变成http://www.domainname.be/nl/

网址http://www.domainname.be变成http://www.domainname.be/nl/

网址http://domainname.be/nl/custompage/变成http://www.domainname.be/nl/custompage/

?

重写条件

RewriteCond %{HTTP_HOST} ^domainname.be [NC]
RedirectRule ^(.*)$ http://www.domainname.be$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^domainname.be [NC]
RewriteCond %{REQUEST_URI} ^/$
RedirectRule ^(.*)$ http://www.domainname.be/nl$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domainname.be [NC]
RewriteCond %{REQUEST_URI} ^/$
RedirectRule ^(.*)$ http://www.domainname.be/nl$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/nl/custompage /Custompage.aspx?lang=nl [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/nl/custompage/ /Custompage.aspx?lang=nl [L,NC]

但是是行不通的。另外,您是否需要清除浏览器缓存才能获得最新情况?

4

1 回答 1

0

删除所有现有规则并使用:

RewriteCond %{HTTP_HOST} ^(www\.)?domainname\.be$ [NC]
RedirectRule ^((?!nl/).*)$ http://www.domainname.be/nl/$1 [R=301,L]

是的,在不同的浏览器中测试它以避免 301 缓存问题。

于 2014-06-10T17:50:55.053 回答