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 aboutRewriteCond %{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.
精彩评论