排除某些页面被重定向到 https
Excluding certain pages from being redirected to https
我在我的 WordPress 网站上使用以下规则:
- 将所有 http 页面重定向到 https
将职业页面重定向到 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/ [R,L]
# Go to http if you are on careers
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/careers$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/ [R,L]
</IfModule>
https
重定向工作正常;但是,职业页面不会重定向到 http
。知道为什么吗?
这是我在 wp-config.php
中的内容
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
尝试使用 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/ [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/ [R,L]
</IfModule>
THE_REQUEST
变量表示 Apache 从您的浏览器收到的原始请求,并且在执行某些重写规则后它不会被覆盖。此变量的示例值为 GET /index.php?id=123 HTTP/1.1
.
确保这些规则位于 WP 默认规则之上。
我在我的 WordPress 网站上使用以下规则:
- 将所有 http 页面重定向到 https
将职业页面重定向到 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/ [R,L] # Go to http if you are on careers RewriteCond %{SERVER_PORT} !80 RewriteCond %{REQUEST_URI} ^/careers$ [NC] RewriteRule ^(.*)$ http://www.mywebsite.com/ [R,L] </IfModule>
https
重定向工作正常;但是,职业页面不会重定向到 http
。知道为什么吗?
这是我在 wp-config.php
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
尝试使用 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/ [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/ [R,L]
</IfModule>
THE_REQUEST
变量表示 Apache 从您的浏览器收到的原始请求,并且在执行某些重写规则后它不会被覆盖。此变量的示例值为 GET /index.php?id=123 HTTP/1.1
.
确保这些规则位于 WP 默认规则之上。