RE: .htaccess - how to force "www." in a generic way?
I asked this question before, and got this answer:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
It works, but now I am seeing 301 Moved Permanently
in the response headers. I want to eliminate the 301s. Is the problem the 2nd rewrite condition? Should it be something like "does not start with 'www.' followed by the host name"?
By the way, I want this solution to work for any server (meaning, I don't want to hard code my domain name).
Suggestions?
UPDATE:
I just realized that the above is not working correctly. If I have the following:
http://images.domain.com
I don't want that to change to:
http://www.images.domain.com
I don't want th开发者_如何转开发is affecting sub-domains. I only want it to affect missing www
.
Redirecting to a different domain is by definition not possible without some header redirect. If you want the URL in the user's browser to change, you have to force a new request. There is no way around that.
You will have to take your pick - the 301
, 302
and 303
status codes being the most straight forward choices.
精彩评论