简体   繁体   English

.htaccess将所有URL重定向到https(不包括特定查询字符串)

[英].htaccess redirect all URLs to https excluding specific query string

I have some rules that force any http URL to be rewritten with https These rules should only apply for a specific HTTP Host (ie if the user is accessing the site through a specific subdomain name). 我有一些规则强制使用https重写任何http URL。这些规则应仅适用于特定的HTTP主机(即,如果用户通过特定的子域名访问网站)。

All working good, but now I want to disable the https redirect if the user is accessing a specific URL 一切正常,但是现在如果用户正在访问特定的URL,我想禁用https重定向

eg http://subdomain.domain.com/test/abc.html or http://subdomain.domain.com/test/123456.html 例如http://subdomain.domain.com/test/abc.htmlhttp://subdomain.domain.com/test/123456.html

This is my code, but Apache seems to be ignoring my 2nd last line 这是我的代码,但是Apache似乎忽略了我的第二行

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/test/
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

Have your rule like this: 规则如下:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+talent/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=302]

Better to use %{THE_REQUEST} since 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}因为THE_REQUEST变量表示Apache从您的浏览器收到的原始请求,并且在执行某些重写规则后不会被覆盖。

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

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