需要通过 mod_rewrite 访问 www - 需要附加条件吗?

发布于 2024-09-10 04:44:54 字数 466 浏览 0 评论 0原文

要将 example.com 重写为 www.example.com,我被告知要在根 .htaccess 文件中使用以下规则:

# Require the www
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/robots\.txt$
RewriteCond %{REQUEST_URI} !^/sitemap\.xml$
RewriteCond %{REQUEST_URI} !^/favicon\.ico$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

您能否解释一下这里的前五行有什么问题?他们真的需要/推荐吗? TIA

To rewrite example.com to www.example.com I was told to use the following rules within my root .htaccess file:

# Require the www
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/robots\.txt$
RewriteCond %{REQUEST_URI} !^/sitemap\.xml$
RewriteCond %{REQUEST_URI} !^/favicon\.ico$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Could you please explain what's the matter with the first five lines here? Are they really needed/recommended? TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

一抹微笑 2024-09-17 04:44:54

.htaccess 技巧 本文将帮助您了解有关 htaccess 的所有技巧。稍后你自己决定是否需要前五行

希望有帮助

.htaccess tricks This article will help you to understand all the tricks about htaccess . Later yourself decide whether you need first five lines

Hope its helpful

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