【问题标题】:force https on a single page, and then redirect other requests to http在单个页面上强制 https,然后将其他请求重定向到 http
【发布时间】:2013-03-19 03:51:24
【问题描述】:

你好,所以基本上我有一个页面,我想拥有 https,我希望它的孩子和兄弟姐妹只有 http。

我的代码可以正常工作,但是如果我单击从我的 ssl 页面到非 ssl 页面的链接,https 仍然存在。我试图让它重定向回 http

这是我目前所拥有的

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^prepaid/?$ https://www.domain.com/prepaid/ [R=301,L]

RewriteRule ^prepaid/h2o/?$  index.php?p=prepaid&s=h2o [L]
RewriteRule ^prepaid/?$      index.php?p=prepaid       [L]

主要目标是始终强制使用 www 以及尾部斜杠 还想仅在 https://www.domain.com/prepaid/ 上强制 https,然后任何 childeren 或 sibliligs 我试图强制 http。即使您在 https 页面上并且点击离开(这是我坚持的内容,它目前停留在 https 中)

【问题讨论】:

  • 您真的应该将链接更新为完整路径,即指定 http://example.com/foo.html,而不仅仅是 foo.html,这样除了在该页面上强制 ssh 外,别无他法,即单个 RewriteCond/RewriteRule 组合。

标签: php html apache .htaccess mod-rewrite


【解决方案1】:

试试这个:

<Location /sample.php>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</Location>

将 sample.php 重命名为您的文件名

【讨论】:

  • 那行不通,该文件是通用模板获取文件(index.php),页面因获取变量不同(index.php?p=prepaid)
  • 将 sample.php 替换为 index.php?p=prepaid 我希望它应该可以工作
猜你喜欢
  • 1970-01-01
  • 2016-07-28
  • 2018-03-14
  • 1970-01-01
  • 2013-01-22
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
  • 2020-05-28
相关资源
最近更新 更多