【问题标题】:Redirect all Wordpress pages to SSL apart from one将所有 Wordpress 页面重定向到 SSL,除了一个
【发布时间】:2015-08-20 15:11:49
【问题描述】:

我想将我的 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

有什么建议吗?

【问题讨论】:

  • 你不想重定向/parent-page/child-page/
  • 没错。我在 Wordpress 声明之后添加了它,因为我认为它不起作用,因为尚未生成永久链接。还是不行。

标签: wordpress .htaccess mod-rewrite ssl


【解决方案1】:

你总是需要你的重定向规则是内部重写的规则。否则,内部内容(如/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

请注意,您还需要在%{REQUEST_URI} 条件中添加一个/ 前导斜杠,这些条件始终以/ 开头。此外,您需要使用该 URI 重定向到 https,因此您需要在重定向到 https 时添加否定排除条件。

【讨论】:

  • 谢谢。似乎更接近我的目标,但有问题的页面现在只是重定向到主页。
  • 还有什么建议吗?
  • @Robert 在重定向到主页的规则中没有任何内容,可能是其他原因。
  • 我刚刚从他的文件中删除了所有其他内容,但仍然遇到同样的问题。在 Wordpress 中,我应该将网站 URL 设置为包含 HTTPS 吗?
  • @Robert 如果您在 Wordpress 中设置重定向,它不会尊重,甚至不兼容您在 htaccess 中放置的重定向。 wordpress 和 htaccess 文件中的规则都不知道对方。
猜你喜欢
  • 2010-10-18
  • 1970-01-01
  • 2015-09-21
  • 1970-01-01
  • 2016-11-08
  • 2012-10-29
  • 2019-10-21
  • 2013-08-01
  • 1970-01-01
相关资源
最近更新 更多