开发者

REGEX .htaccess RewriteCond parameter forming

How do I specify in .htacess that I want an action to be performed for all URLs beginning with www.domain.com?

I thought about

RewriteCond %{HTTP_HOST} ^www.domain.com(.*)$ [NC]

but it's wrong.

Also tried

RewriteCond %{HTTP_HOST} ^www.domain.com(?:.*)?$开发者_如何学C [NC]

but isn't any better.


You have chosen to check against HTTP_HOST and make a decision based on that. HTTP_HOST only contains the hostname requested, and no slashes or parts of the full URL. Because of that, I would remove the (.*) or (?:.*)? at the end of your RewriteConds and check again. At least, that's how I use it.

If you're attemping to redirect a www to a non-www (just guessing) and want to make sure the requested path is transferred, this is my code:

RewriteCond %{HTTP_HOST} ^www\..* [NC]
RewriteRule ^(.*)$ http://nonwwwdomain.com%{REQUEST_URI} [R=301,L]

It uses a 301 "Moved Permanently" redirect for search engines.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜