【问题标题】:Mod rewrite rules doesnt work if url contains https:// in the middle如果 url 中间包含 https://,则 Mod 重写规则不起作用
【发布时间】:2018-04-05 19:59:42
【问题描述】:

我需要重写网址:

http://example.com/key/https://.pictureurl.jpg

http://pictureurl.jpg

但是这个不起作用,我想知道为什么:

RewriteEngine On
RewriteBase /
RewriteRule ^key/https://(.*)$ $1 [R,L]

所以它最终应该被重定向到http://pictureurl.jpg 然而事实并非如此。它被重定向到:

http://www.https.com/pictureurl.jpg

这是一个无效的网址。为什么会这样以及如何解决它。谢谢。

【问题讨论】:

  • 不确定您的网址会是什么样子。也许:RewriteRule ^.*key/https://\.(.*)$ http://$2 [R,L]

标签: regex apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

试试这个重写规则

RewriteEngine On
RewriteBase /
RewriteRule ^key/https://\.(.*)$ //$1 [R,L]

我测试了它here,它似乎工作。

【讨论】:

    【解决方案2】:

    问题是 mod_rewriteRewriteRule 模式中将多个斜杠剥离为一个斜杠

    您可以使用RewriteCond 来匹配您的URI 中的https://,如以下规则所示:

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} ^/key/https://(.+)$ [NC]
    RewriteRule ^ /%1 [L,NE,R=301]
    

    确保在测试时清除浏览器缓存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-31
      • 2015-07-26
      • 2014-10-10
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 2015-08-17
      • 1970-01-01
      相关资源
      最近更新 更多