无法进行 301 域重定向
您好,我有一个使用 opencart 的应用程序。我想在用户输入 http://example.com 时进行 301 重定向。在 http://www.example.com 中重定向(301 状态代码)
这是我的 .htaccess 内容:
RewriteEngine On
\#OPENCART REWRITES START
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
\#OPENCART REWRITES END
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
我得到 302 重定向而不是 301。
谢谢, 花岗岩
Hi I have an application which uses opencart. I would like to make a 301 reditect in case the user types http://example.com. To be redirected in http://www.example.com (301 status code)
Here is my .htaccess content:
RewriteEngine On
\#OPENCART REWRITES START
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
\#OPENCART REWRITES END
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I get 302 redirection instead of 301.
Thanx,
Granit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过这样做:
强调第二行,因为它与 http://example.com 匹配,而不是匹配反对除 www.example.com 之外的任何内容,如果您碰巧使用子域名,该域名将会崩溃。我不确定这是否与您的 301/302 问题完全相关,但它可能会产生影响。另外,尝试一下您的规则 [R=301,NC,L]。
Have you tried doing:
Emphasis on the second line, as it matches against http://example.com as opposed to matching against anything-but www.example.com, which will break if you happen to use subdomains. I'm not sure if this is exactly related to your 301/302 issue, but it could have an affect. Also, try on your Rule [R=301,NC,L].
尝试使用不同的顺序。将导致外部重定向的规则放在仅导致内部重定向的规则之前:
Try it with a different order. Put your rules that cause an external redirect before those that only cause an internal redirect: