简体   繁体   English

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

[英]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 . 它们应同时在httphttps上工作。 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.

相关问题 .htaccess重定向到https和www。 如果启用 - .htaccess redirect to https and www. if enabled .htaccess文件没有重定向http:// www。 到https:// www - .htaccess file not redirecting http://www. to https://www htaccess强制https和www。 在域上&http在子域上没有www - htaccess force https & www. on domain & http no www on subdomain htaccess将http://(www。)old.com和https://(www。)old.com重定向到https:// new - htaccess redirecting http://(www.)old.com and https://(www.)old.com to https://new 使用https://和www。 在子目录中有cloudflare - Use https:// AND www. with cloudflare in subdirectories htaccess重定向https:// www。 (https://www.example.com)到非www(https://example.com) - htaccess redirect https://www. (https://www.example.com) to non www (https://example.com) htaccess http到带有www的https。 不重定向子域 - htaccess http to https with www. Without redirecting sub domain htaccess 在带走 www 时恢复到 php url。 或 https - htaccess reverting to php url when taking away www. or https .htaccess 强制使用 HTTPS,在某些情况下使用 www。 但不包括特定的子域 - .htaccess Forcing HTTPS and in some cases www. but excluding specific subdomains Getting .htaccess redirects from one domain to another to work for WWW ( both http://www. and https://www.), HTTP and HTTPS - Getting .htaccess redirects from one domain to another to work for WWW ( both http://www. and https://www.), HTTP and HTTPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM