简体   繁体   English

不带https的类别URL重定向到magento中的主页

[英]category url without https redirect to homepage in magento

we have enabled https in our website and enabled 301 in admin section. 我们在网站上启用了https,并在管理部分启用了301。

But the issue is with the category urls. 但是问题在于类别网址。 Suppose if we select http:// www.testsite.com/ category.html, it will redirect to homepage. 假设我们选择http:// www.testsite.com/ category.html,它将重定向到主页。 So after some searching i found a solution, which told me to add 因此,经过一番搜索,我找到了一个解决方案,告诉我要添加

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https:// %{HTTP_HOST}%{REQUEST_URI} [L,R=301]

after
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] in .htaccess RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] .htaccess中的RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Now this url http:// www.testsite.com/ category.html redirects to https:// www.testsite.com/ category.html. 现在,此URL http:// www.testsite.com/ category.html重定向到https:// www.testsite.com/ category.html。 But for this url http:// testsite.com/ category.html, it redirects to homepage. 但是对于此URL http:// testsite.com/ category.html,它将重定向到主页。 I think some tweak on the above code is required. 我认为需要对上述代码进行一些调整。 Could anybody help me in this please. 有人可以帮我吗。

Looks like you're simply trying to force the WWW and force the HTTPS. 看起来您只是在尝试强制WWW和HTTPS。 While this should typically be done inside of a virtualhost configuration, I can understand if that's not an option. 尽管通常应在虚拟主机配置中完成此操作,但我可以理解这是否不是一种选择。

The solution is simple, and is as follows: 解决方案很简单,如下所示:

# Start the Rewrite Engine
RewriteEngine On

#Set the base url to / unless you're in a subdirectory, so not modify this.
RewriteBase /

#Redirect all requests to WWW.
RewriteCond %{HTTP_HOST} ^testsite\.com
RewriteRule (.*) http://www.testsite.com/$1 [R=301,L]

# If requests are made on port 80, rewrite to HTTPS which will server over port 443.
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://testsite.com/$1 [R,L]

If you're looking to only redirect specific subdirectories, or pages, simply append the path to the condition and rules above. 如果您只想重定向特定的子目录或页面,只需将路径追加到上述条件和规则即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM