繁体   English   中英

.htaccess将所有http重定向到https,另一种方式

[英].htaccess redirect all http to https and one the other way

我需要将除一个以外的所有请求重定向到https,如果使用https访问,则应将其重定向到http。 另外,我需要标准php重写,以便所有土地都在index.php中。 将所有内容重定向到https都很容易。 我可以使它以一种https-> http的方式工作,但是如果我取消注释这些行,我将从http://example.com/bye重定向到https://example.com/index.php 我想念什么?

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/bye$
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L]

#RewriteCond %{HTTPS} off
#RewriteCond %{REQUEST_URI} !^/bye$
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

您需要使用THE_REQUEST变量,因为最后一条规则将REQUEST_URI变量更改为/index.php

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/+bye/?[?\s]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+bye/?[?\s]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

暂无
暂无

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

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