[英]Htaccess: Use https://www. with exceptions
I want to redirect every request in my website to https://www. 我想将网站中的每个请求重定向到https:// www。 and also tunnel everything to index.php
并将所有内容传输到index.php
There are two exceptions for the urls of the like: like的网址有两个例外:
http://www.example.com/share/AAAAA http://www.example.com/share/AAAAA
https://www.example.com/share/BBBBB https://www.example.com/share/BBBBB
and 和
http://www.example.com/loader/AAAAA http://www.example.com/loader/AAAAA
https://www.example.com/loader/BBBBB https://www.example.com/loader/BBBBB
(AAAA and BBBB can be anything) (AAAA和BBBB可以是任何东西)
For these urls i want it to always use www but the https must not be mandatory. 对于这些网址,我希望它始终使用www,但是https一定不是必需的。 They should work both on http and https .
它们应同时在http和https上工作。 This is my htaccess so far:
到目前为止,这是我的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]
This is working for the rest of the pages, except for the exceptions. 这适用于其余页面(例外除外)。 If i enter
如果我输入
http://www.example.com/share/AAAAA http://www.example.com/share/AAAAA
in the browser it redirects me to 在浏览器中,它将我重定向到
https://www.example.com/index.php?rest=share/AAAAA https://www.example.com/index.php?rest=share/AAAAA
So not only it adds https , but it also shows the ?rest stuff in the url. 因此,不仅添加了https ,而且还在URL中显示了?rest内容。 Note that the ?rest= problem is not happening with all the other links.
请注意,所有其他链接都没有发生?rest =问题。 This should be tunneling in the background.
这应该在后台进行隧道传输。
Use THE_REQUEST
instead of REQUEST_URI
variable: 使用
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
variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules. THE_REQUEST
变量表示Apache从您的浏览器收到的原始请求,在执行某些重写规则后不会被覆盖。 Example value of this variable is GET /index.php?id=123 HTTP/1.1
此变量的示例值为
GET /index.php?id=123 HTTP/1.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.