我想将http重定向到https两个类别(商店和大学),其他我想重定向到http

时间:2015-12-11 12:41:05

标签: php .htaccess redirect

这不行,我从商店和大学获得了许多重定向

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
#RewriteCond %{REQUEST_URI} ^/shop$ [NC]
RewriteRule ^(shop/.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /shop/
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(university/.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /university/


</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^(shop/.*)$ [NC]
RewriteCond %{REQUEST_URI} !^(university/.*)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

</IfModule>

如何制作正确的重定向?

1 个答案:

答案 0 :(得分:0)

您可以使用:

<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>