我在WordPress网站上使用以下规则:
将职业页面重定向到http
<IfModule mod_rewrite.c>
RewriteEngine On
# Go to https if not on careers
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/careers$ [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
# Go to http if you are on careers
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/careers$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L]
</IfModule>
https
重定向工作正常;但是,职业页面不会重定向到http
。知道为什么吗?
这是wp-config.php
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
答案 0 :(得分:2)
尝试使用THE_REQUEST
代替REQUEST_URI
:
<IfModule mod_rewrite.c>
RewriteEngine On
# Go to https if not on careers
RewriteCond %{SERVER_PORT} =80
RewriteCond %{THE_REQUEST} !/careers/[\s?] [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
# Go to http if you are on careers
RewriteCond %{SERVER_PORT} !=80
RewriteCond %{THE_REQUEST} /careers/[\s?] [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L]
</IfModule>
THE_REQUEST
变量表示Apache从您的浏览器收到的原始请求,并且在执行某些重写规则后不会被覆盖。此变量的示例值为GET /index.php?id=123 HTTP/1.1
。
确保将这些规则置于WP默认规则之上。