OpenCart htaccess重定向到WWW和SSL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCart htaccess重定向到WWW和SSL相关的知识,希望对你有一定的参考价值。

我想使用opencart强制将OpenCart存储重定向到其WWW版本。

SEO URL Settings

RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这是重定向的htaccess部分,它可以工作但智能URL现在是

https://www.example.com/index.php?route=the-name-of-the-product,它应该是https://www.example.com/the-name-of-the-product

知道如何用智能网址解决这个问题吗?我在重定向错误还是其他问题?

答案

尝试在.htaccess文件的开头移动以下行

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

以上是关于OpenCart htaccess重定向到WWW和SSL的主要内容,如果未能解决你的问题,请参考以下文章

为啥我的 .htaccess 文件的 301 重定向不能正常工作?

.htaccess:将主域重定向到https:// www,子域重定向到https://(不带www)

markdown [www和https重定向]将所有文件重定向到https url和www域名#www #htaccess

nginx 上的 OpenCart

htaccess 重定向到 https 和 www 不起作用

htaccess 重定向非 www http 和 https