简体   繁体   English

使用.htaccess,允许通过HTTPS://提供特定的Wordpress页面集,并将所有其他页面重定向回HTTP://

[英]With .htaccess, allow a specific set of Wordpress pages to be served over HTTPS://, and redirect all others back to HTTP://

I only want a specific set of pages on my Wordpress website to be served over https. 我只希望通过https提供我的Wordpress网站上的一组特定页面。 All other pages should redirect back to http://. 所有其他页面应重定向回http://。

Using the below .htaccess rewrite rules I can successfully redirect unwanted https:// requests back to http://, but when I try to access one of my allowed https:// pages it redirects back to my blog's homepage for some reason. 使用以下.htaccess重写规则,我可以成功地将不需要的https://请求重定向回http://,但是当我尝试访问允许的https://页面之一时,由于某种原因,它会重定向回到博客的首页。

https:// mywebsite.com/blog/random-page >>>> http:// mywebsite.com/blog/random-page/ (Good) https:// mywebsite.com/blog/random-page >>>> http:// mywebsite.com/blog/random-page/(良好)

https:// mywebsite.com/blog/ssl-page >>>> http:// mywebsite.com/blog/ (Bad, this URL shouldn't be redirecting at all.) https:// mywebsite.com/blog/ssl-page >>>> http:// mywebsite.com/blog/(糟糕,此URL根本不应重定向。)

I'm not sure what's going on, I think there is a conflict between my RewriteCond's? 我不确定发生了什么,我认为我的RewriteCond之间有冲突吗? Any help would be appreciated! 任何帮助,将不胜感激! Thank you 谢谢

My .htaccess file 我的.htaccess文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/blog/ssl-page/ [NC]
RewriteCond %{REQUEST_URI} !^/blog/another-ssl-page/$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

For that specific example, the problem is here: 对于该特定示例,问题在这里:

RewriteCond %{REQUEST_URI} !^/blog/ssl-page/ [NC]

You state that /blog/ssl-page redirects to HTTP. 您声明/blog/ssl-page重定向到HTTP。 It's because your first RewriteCond isn't matched - it expects a trailing slash. 这是因为您的第一个RewriteCond不匹配-它需要一个斜杠。

You can try this: 您可以尝试以下方法:

RewriteCond %{REQUEST_URI} !^/blog/ssl-page/?$ [NC]

to make the trailing slash optional. 使尾部斜杠为可选。

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

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