【问题标题】:rewriting rules end up with 'page not found' on https pages重写规则最终在 https 页面上出现“找不到页面”
【发布时间】:2012-03-08 00:03:22
【问题描述】:

我的网站上有多个重写规则,如下所示

 ^product/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ /index.php?action=product&category=$1&type=$2

我还安装了自签名 ssl 证书和几个 php 重定向到 https 的页面。当我在这样的 https 页面上并单击与上述重写规则匹配的链接时,我最终会出现“未找到”错误页面

如何告诉apache所有的重写规则都应该相对于http而不是https来读取?

编辑: 我通过在 :443 Virtual Host 下添加重写规则的副本来整理它

【问题讨论】:

    标签: php apache mod-rewrite https


    【解决方案1】:

    假设您的 Apache 在标准端口上提供 HTTPS,您可以在规则前添加条件:

    RewriteCond %{SERVER_PORT} =443
    RewriteRule ...
    

    编辑:还有另一个变量,您可以检查一下(它也在 documentation 中):

    HTTPS

    如果连接使用 SSL/TLS,将包含文本“on”,否则将包含文本“off”。 (无论是否加载了 mod_ssl,这个变量都可以安全使用)。

    所以这应该会更好,不管 SSL 是通过哪个端口传送的:

    RewriteCond %{HTTPS} =off
    RewriteRule ...
    

    【讨论】:

    • RewriteCond %{HTTPS} =off 和 RewriteCond %{SERVER_PORT} =443 都没有帮助。在点击例如 [https]://product/jewellery/rings 时,我仍然“找不到”
    • 嗯。然后你需要发布你的整个规则集。可能还有其他问题。
    【解决方案2】:

    你可以试试:

    RewriteCond %{HTTPS} on
    

    看看htaccess HTTPS / SSL Tips, Tricks, and Hacks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多