mod_rewrite 重定向之间的区别?
我有以下两个 mod_rewrite 重定向。它们似乎都做同样的事情,但我不确定为什么一个比另一个长两行。 (顺便说一句,我一直在使用较长的一个):
1:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ shows [L]
2:
RewriteEngine On
RewriteRule ^$ /shows [L]
I have the following two mod_rewrite redirects. They both appear to do the same thing, but I'm not sure why one is two lines longer than the other. (I've been using the longer one btw):
1:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ shows [L]
2:
RewriteEngine On
RewriteRule ^$ /shows [L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
额外的两行只是将对
example.com
上的任何页面的请求转发到www.example.com
上的同一页面,执行 301 永久重定向(因此R=301...
)。最好不要在两个域上出现重复的内容(出于 SEO 目的),因此现在大多数人将
example.com
转发到www.example.com
;另一种方式也完全有效并且广泛使用(即将www.example.com
重定向到example.com
)。The extra two lines simply forward requests for any page at
example.com
to the same page atwww.example.com
, performing a 301 permanent redirect (hence theR=301...
).It's good practice not to have duplicate content on two domains (for SEO purposes) so most people these days forward
example.com
towww.example.com
; the other way around is also perfectly valid and quite widely used (ie. redirectingwww.example.com
toexample.com
).