这两次重写是一样的吗?
以下有何不同?忽略域名。
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule (.*) http://www.yourdomain.com/$1 [L,R=301]
区别是“^”?
我基本上想做的是将我的网站设置为 http://yourdomain.com 并且永远不会出现 www 。首先,它的长度较短,并且有利于搜索引擎优化,因为我的网站不会被视为两个网站。一种带 www,一种不带 www。
谢谢大家
How are the following different? Ignore the domain names.
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule (.*) http://www.yourdomain.com/$1 [L,R=301]
The difference is "^"?
What I basically want to do is have my site as http://yourdomain.com and never have the www appear. For a start its shorter and its good for SEO as my site won't be judged as two sites. One with www and one without.
Thanks all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,它们不一样。
第一个表示,如果主机是
www.example.com
,则重定向到主机example.com
。第二个表示,如果主机不是
www.example.com
,则重定向到www.example.com
。即使您将第二个重写为以下内容(两条规则都重定向到
example.com
:这样,如果主机不是
example.com
,它将重定向到example.com
如果主机只能是www.example.com
和example.com
,则结果可能相同。如果有更多的值(例如foobar.example.com
),您的第一条规则不会重定向,而我的会重定向。No, they are not the same.
The first says, redirect to the host
example.com
if the host iswww.example.com
.The second says, redirect to
www.example.com
if the host is notwww.example.com
.And even if you would rewrite the second to the following (having both rules redirecting to
example.com
:So that it would redirect to
example.com
if the host is notexample.com
. The result might be the same if the host can only bewww.example.com
andexample.com
. But if it can have more values than that (e.g.foobar.example.com
), the your first rule would not redirect while my would redirect.