繁体   English   中英

htaccess:使用https:// www。 有例外

[英]Htaccess: Use https://www. with exceptions

我想将网站中的每个请求重定向到https:// www。 并将所有内容传输到index.php

like的网址有两个例外:

http://www.example.com/share/AAAAA

https://www.example.com/share/BBBBB

http://www.example.com/loader/AAAAA

https://www.example.com/loader/BBBBB

(AAAA和BBBB可以是任何东西)

对于这些网址,我希望它始终使用www,但是https一定不是必需的。 它们应同时在httphttps上工作。 到目前为止,这是我的htaccess:

ErrorDocument 403 /403.php

RewriteEngine On

#USE HTTPS
RewriteCond %{REQUEST_URI} !^/(share/|loader/)
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,QSA]

#ALWAYS USE www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?rest=$1 [L,QSA]

这适用于其余页面(例外除外)。 如果我输入

http://www.example.com/share/AAAAA

在浏览器中,它将我重定向到

https://www.example.com/index.php?rest=share/AAAAA

因此,不仅添加了https ,而且还在URL中显示了?rest内容。 请注意,所有其他链接都没有发生?rest =问题。 这应该在后台进行隧道传输。

使用THE_REQUEST而不是REQUEST_URI变量:

ErrorDocument 403 /403.php
RewriteEngine On

#USE HTTPS
RewriteCond %{THE_REQUEST} !\s/+(share/|loader/)
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

#ALWAYS USE www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?rest=$1 [L,QSA]

THE_REQUEST变量表示Apache从您的浏览器收到的原始请求,在执行某些重写规则后不会被覆盖。 此变量的示例值为GET /index.php?id=123 HTTP/1.1

暂无
暂无

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

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