简体   繁体   English

如何将特定文件夹从HTTP重定向到HTTPS

[英]How to redirect specific folder from HTTP to HTTPS

I am struggling to redirect only my e-shop located in the folder called shop . 我正在努力仅重定向位于名为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. 我有2个htaccess文件,一个在域根目录(一个专用于公司网站),另一个在shop文件夹中。 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: 如果将其放入商店的htaccess文件中,则会收到重定向循环错误:

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

This doesn't do anything in both htaccess files: 这在两个htaccess文件中都不起作用:

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: 当我将其放入文档根目录下的htaccess文件中时,这都不是:

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: 它位于文档根目录下的htaccess中:

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: 而这在商店的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 您的第一个规则是正确的,您只需添加一个R标志

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

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

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