简体   繁体   中英

How to redirect specific folder from HTTP to HTTPS

I am struggling to redirect only my e-shop located in the folder called shop . I have 2 htaccess files, one is on the domain root (the one dedicated for the corporate website) and the other one placed in the shop folder. I've tried many variations of the rewrite rule, but I can't make it to work...

If I put this into the shop's htaccess file i get the redirect loop error:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This doesn't do anything in both htaccess files:

RewriteEngine on
RewriteCondition %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.maindomain.com/order/$1 [R=301,L]

Neither this when i put it into the htaccess file located on the document root:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(subdirectory/.*)$ https://www.mydomain.com/$1 [R=301,L]

Note: If it makes any difference, I have this redirect rule as well. Its located in the htaccess on the document root:

RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{HTTP_HOST} !^rumako.cz$ [NC]
RewriteRule ^(.*)$ http://rumako.cz/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

And this one in the shop's htaccess:

    RewriteEngine On
    RewriteBase /shop
    RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
    RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [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]

Please advise. Thanks for all answers...

Your first rule is correct, you must only add an R flag

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

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