Apache mod_rewrite:仅在不在本地主机中时才强制www [英] Apache mod_rewrite: force www only if not in localhost
本文介绍了Apache mod_rewrite:仅在不在本地主机中时才强制www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在htaccess中具有以下要求,以在网址中强制使用www:
I have the following in my htaccess to force the www in URLs:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
如果不在本地主机上,如何仅应用此选项?我可以设置某种if条件吗?现在,我得到的是这样的内容:http://www.localhost/
...
How do I only apply this if not on localhost? Is there some sort of if-condition I can put? Right now, I'm getting something like this: http://www.localhost/
...
推荐答案
RewriteCond
已经是您的"if-condition".只需添加另一个:
RewriteCond
is already your "if-condition". Just add another one:
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
这篇关于Apache mod_rewrite:仅在不在本地主机中时才强制www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文