简体   繁体   中英

category url without https redirect to homepage in magento

we have enabled https in our website and enabled 301 in admin section.

But the issue is with the category urls. Suppose if we select http:// www.testsite.com/ category.html, it will redirect to homepage. 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

Now this url http:// www.testsite.com/ category.html redirects to https:// www.testsite.com/ category.html. But for this url http:// testsite.com/ category.html, it redirects to homepage. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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