English 中文(简体)
Removing www with .htaccess notomping/ redirecting
原标题:Removing www with .htaccess not matching / redirecting

几个小时以来,我一直试图解决与./ mo改有关的问题,但我确实能够说明问题是什么。

# 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

http://www.static.domain.nl

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!

最佳回答

您的加入规则如下:

# 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]
问题回答

我假定第3条是ski熟的,但第1条是一纸空文。

Try to change it.





相关问题
How to use redirect_to to a non-Rails URL with query params?

We just had an existing use of redirect_to break due to a Rails upgrade, and it led to a question. I ve been experimenting, and I don t seem to find a way to use redirect_to to send the user to a non-...

Apache authentication: Redirect on failure, reliably?

I ve set my ErrorDocument 401 to point to my website s account creation page, but not all browsers seem to honor this redirect (Safari). Also, other browsers (Firefox, Chrome) never quit asking for ...

Response.Redirect HTTP status code

Why is it that ASP/ASP.NET Response.Redirect uses a HTTP-302 status code ("Moved Temporarily") even though in most cases a HTTP-301 status code ("Moved Permanently") would be more appropriate?

Exceptions: redirect or render?

I m trying to standardize the way I handle exceptions in my web application (homemade framework) but I m not certain of the "correct" way to handle various situations. I m wondering if there is a ...

Cakephp is not redirecting properly when pages are cached

I am having some issues with a site that was working correctly until i implemented full page caching in CakePHP. I have followed the guidance in the Manual and have my $session->flash in a no-cache ...

热门标签