将非 www 重定向到 www 不起作用
我使用 virtualmin 设置了一个虚拟服务器,它没有创建 .htaccess 文件,所以我在 public_html 文件夹中创建了一个文件,并放入以下代码
RewriteEngine On
RewriteCond % ^megahotserved.com [NC]
RewriteRule ^(.*)$ http://www.megahotserved.com/$1 [L,R=301]
重新启动 apache,但没有效果,然后
<VirtualHost *:80>
ServerName megahotserved.com
Redirect permanent / http://www.megahotserved.com/
</VirtualHost>
在重新启动 apache 时在 httpd.conf 文件中 尝试火狐出现了一个错误
页面未正确重定向。
Firefox 检测到服务器正在以永远无法完成的方式重定向对此地址的请求。
我应该怎么办 ?
I set up a virtual server using virtualmin, it didn't create the .htaccess file so I created one in the public_html folder and put the following code
RewriteEngine On
RewriteCond % ^megahotserved.com [NC]
RewriteRule ^(.*)$ http://www.megahotserved.com/$1 [L,R=301]
restarted apache and no effect and then tried
<VirtualHost *:80>
ServerName megahotserved.com
Redirect permanent / http://www.megahotserved.com/
</VirtualHost>
in the httpd.conf file, when I restarted apache firefox came up with an error
The page isn't redirecting properly.
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
What should I do ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的代码是正确的,您只需遵循我引用的下一段 http: //httpd.apache.org/docs/current/mod/mod_rewrite.html
your code is correct, you just need to follow the next paragraph which I quoted from http://httpd.apache.org/docs/current/mod/mod_rewrite.html
似乎您没有与
www.
地址正确匹配的 VirtualHost,因此对http://www.megahotserved.com/
的请求正在访问同一个虚拟主机并进入循环重定向。所以重定向工作正常;您只需修复服务器配置的不同部分即可。Seems like you don't have a VirtualHost that properly matches the
www.
address, so requests forhttp://www.megahotserved.com/
are hitting the very same vhost and getting into a circular redirect. So the redirect is working fine; you just have a different part of the server config to fix.同意上面的内容,还有一点补充:最好将非 www 重定向到 www,而不是重写,否则您将拥有整个网站的两个完整视图(“副本”);每个页面都有两个 URL,而不是一个规范 URL。这可能对搜索引擎和其他事物不利。
Agree with the above, and a small addition: it is better to redirect non-www to www rather than rewrite, otherwise you have two complete views ("copies") of your entire website; each page has two URLs, instead of one canonical one. This can be bad for search engines and other things.