将所有Wordpress页面重定向到SSL除外

Rob*_*ffe 2 wordpress .htaccess mod-rewrite ssl

我想将我的Wordpress网站上的所有页面重定向到SSL除了一个.

我已经尝试了很多方法来做到这一点,并成功地使SSL工作,但我不能让单页排除工作.

我假设问题在于Wordpress特定的重写.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{REQUEST_URI} ^parent-page/child-page/
RewriteCond %{HTTPS} on   
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud)

有什么建议?

Jon*_*Lin 5

您始终需要重定向到内部重写规则之前的规则.否则,内部资料(如/index.php)最终会被重定向.

尝试:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^/parent-page/child-page/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteCond %{REQUEST_URI} ^/parent-page/child-page/
RewriteCond %{HTTPS} on   
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud)

请注意,您还需要在条件中添加/前导斜杠%{REQUEST_URI},这些斜杠始终以a开头/.此外,你需要重定向到https与URI,所以你需要一个负的排除条件添加到重定向到HTTPS.