我用过这段代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(shop|university)(/.*)?$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
RewriteCond %{HTTPS} on
RewriteRule !^(shop|university)(/.*)?$ http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
</IfModule>
我想将 http 重定向到 https 两个类别(商店和大学),其他我想重定向到 http
但是,在将规则安装到所有 https 后,我会在 http 上转移我,但从 universiti 和商店放在主页上。会是什么?
最佳答案
尝试:
<IfModule mod_rewrite.c>
RewriteEngine On
#https to http
RewriteCond %{HTTPS} ^on$
RewriteCond %{REQUEST_URI} !^/(shop|university)/
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
#http to https
RewriteCond %{HTTPS} ^off$
RewriteCond %{REQUEST_URI} ^/(shop|university)/
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
</IfModule>
关于.htaccess - 从 htaccess 重定向(https 到 http),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34267570/