[英]What is wrong with these rewrite rules? Redirect to https for one page, back to http for all others
Desired behavior: 所需行为:
Visiting http://www.example.com/our-services/individual-medical-dental-insurance
redirects to https: https://www.example.com/our-services/individual-medical-dental-insurance
参观
http://www.example.com/our-services/individual-medical-dental-insurance
重定向到https: https://www.example.com/our-services/individual-medical-dental-insurance
Visiting any other page via https, such as https://www.example.com/about-group-benefit-services/
, redirects to non-https: http://www.example.com/about-group-benefit-services/
通过https访问任何其他页面 ,例如
https://www.example.com/about-group-benefit-services/
,重定向到非https: http://www.example.com/about-group-benefit-services/
: http://www.example.com/about-group-benefit-services/
I've tried a variety of solutions, and this is my most recent version (which does not work): 我尝试了各种解决方案,这是我的最新版本(不起作用):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} our-services/individual-medical-dental-insurance
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^our-services\/individual\-medical\-dental\-insurance
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/$1
[L,R=301]
</IfModule>
It may be worth noting that this is in a WordPress site, and the remainder of the .htaccess file contains this: 可能值得注意的是,该文件位于WordPress网站中,.htaccess文件的其余部分包含以下内容:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
(The .htaccess does not contain anything other than the above). (.htaccess除以上内容外不包含其他任何内容)。
Not sure if this will make it work but there's a few issues with your rules and it won't fit into a comment: 不知道这是否能使它正常工作,但是您的规则存在一些问题,因此不适合发表评论:
The %{REQUEST_URI}
always starts with a "/" and thus your regex will always be true (since it'll never start with "our-services"). %{REQUEST_URI}
始终以“ /”开头,因此您的正则表达式将始终为true(因为它永远不会以“ our-services”开头)。
The other thing is that your rule is doing the appending of the URL at the end because of the $1
backreference, so you need to remove that. 另一件事是您的规则由于
$1
反向引用而在末尾附加了URL,因此您需要删除它。
Lastly, both redirects are going to https://
. 最后,两个重定向都将转到
https://
。
Also, you don't need to escape the slashes or dashes: 另外,您无需转义斜杠或破折号:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/our-services/individual-medical-dental-insurance
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/our-services/individual-medical-dental-insurance
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.