开发者

Removing 'www' with .htaccess not matching / redirecting

I have been trying to resolve a problem with .htaccess / modrewrite for a few hours now but I really can't figure out what the problem is.

# Rule 1
RewriteCond %{HTTP_HOST} ^www\.domain\.nl.*$
RewriteRule (.*) http://domain.nl/$1

# Rule 2
RewriteCond %{HTTP_HOST} ^www.([a-z0-9]*?)\.domain\.nl.*$
RewriteRule (.*) http://%1.domain.nl/$1

# Rule 3
RewriteCond %{HTTP_HOST} ^([a-z0-9]+?)\.domain\.nl(.*)$
RewriteRule (.*) http://domain.nl/%1/$1

The following url's are rewritten correctly: http://www.static.domain.nl/style/file.css, http://static.domain.nl/style/file.css and http://domain.nl/static/style/file.css, all to http://domain.nl/static/style/file.css

But the result for this one to me seems completely random: http://www.domain.nl/static/style/file.css becomes http://domain.nl/www/http://domain.nl/static/style/file.css .

I think this url should be matched by rule #1 which should cause a redirect (and as such skip rule #2 and #3). However it seems rule #3 is somehow matching this url and causing a very peculiar rewrite.

Very striking observarion: if rule #3 is removed with only #1 and #2 remaining, it works as it should ('www' is removed, rest remains intact).

I have no idea at all what's happening, any clues?

Thanks a 开发者_运维知识库lot!


Have your .htaccess rules like this:

# Rule 1
RewriteCond %{HTTP_HOST} ^www\.domain\.nl
RewriteRule ^ http://domain.nl%{REQUEST_URI} [L,R=301]

# Rule 2
RewriteCond %{HTTP_HOST} ^www.([a-z0-9]*)\.domain\.nl
RewriteRule ^ http://%1.domain.nl%{REQUEST_URI} [L,R=301]

# Rule 3
RewriteCond %{HTTP_HOST} ^([a-z0-9]*)\.domain\.nl
RewriteRule ^ http://domain.nl/%1%{REQUEST_URI} [L,R=301]


I suppose that Rule 3 in skipped but $1 on Rule # 1 mess all up.

Try to change it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜