Apache 正确的htaccess 301以防止重复的主机名问题?
我想确保没有重复的主机名问题,Google Analytics建议有 所以,我想确保我的主页始终是www.example.com,而不是example.com或者我想 这是如何安全完成的 我找到了一个例子,但由于我不是这方面的大师,我想我需要第二个或两个意见:Apache 正确的htaccess 301以防止重复的主机名问题?,apache,.htaccess,mod-rewrite,redirect,hostname,Apache,.htaccess,Mod Rewrite,Redirect,Hostname,我想确保没有重复的主机名问题,Google Analytics建议有 所以,我想确保我的主页始终是www.example.com,而不是example.com或者我想 这是如何安全完成的 我找到了一个例子,但由于我不是这方面的大师,我想我需要第二个或两个意见: RewriteEngine on RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ RewriteRule .? http://www.example.com%{REQUEST_U
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
解释得越多越好 您在
RewriteCond
中的正则表达式看起来可疑,因为它使整个主机名都是可选的。您可以改为使用此规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L,NE]