这两次重写是一样的吗?

发布于 2024-08-10 20:44:14 字数 460 浏览 6 评论 0原文

以下有何不同?忽略域名。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相守太难 2024-08-17 20:44:14

不,它们不一样。

第一个表示,如果主机是 www.example.com,则重定向到主机 example.com
第二个表示,如果主机不是 www.example.com,则重定向到 www.example.com

即使您将第二个重写为以下内容(两条规则都重定向到 example.com

RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule (.*) http://example.com/$1 [L,R=301]

这样,如果主机不是 example.com,它将重定向到 example.com如果主机只能是 www.example.comexample.com,则结果可能相同。如果有更多的值(例如 foobar.example.com),您的第一条规则不会重定向,而我的重定向。

No, they are not the same.

The first says, redirect to the host example.com if the host is www.example.com.
The second says, redirect to www.example.com if the host is not www.example.com.

And even if you would rewrite the second to the following (having both rules redirecting to example.com:

RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule (.*) http://example.com/$1 [L,R=301]

So that it would redirect to example.com if the host is not example.com. The result might be the same if the host can only be www.example.com and example.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文