【问题标题】:Remove double Slashes in URL and remove index.php Apache删除 URL 中的双斜杠并删除 index.php Apache
【发布时间】:2016-08-07 13:32:46
【问题描述】:

感谢您阅读我的问题。

我有一个在 Apache 网络服务器上运行的应用程序 (php)(目前在旧的 apache 2.2.17 上)。现在我将 Apache 升级到 2.4.18。

为了从 url 中删除 index.php,有一个 .htaccess 文件。有了这个规则。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L]  

在某些请求上,应用程序会创建发布请求,例如

http://www.xyz.yz//targetname/targetname2/

双斜杠 // 在 url 路径中。

在 Apache 2.2.17 上,此 URL 没有问题,但 Apache 2.4.18 会产生 404 错误。

我玩了很多这样的重写规则:

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ [NC]
RewriteRule . %1/%2 [R=307,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L]  

但是现在客户端发送了两次 post 请求。那么,例如,我如何在不重写的情况下告诉 apache“忽略”双引号。

感谢您的想法和解决方案。

【问题讨论】:

    标签: php apache .htaccess post


    【解决方案1】:

    要删除域扩展后的多个斜杠,您可以在 htaccess 中的其他规则之前使用以下规则:

    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} //+(.+)\sHTTP
    RewriteRule ^ /%1 [L,R]
    

    这会将多个斜杠转换为一个,

    • example.com////foo

    • example.com/foo

    【讨论】:

      猜你喜欢
      • 2018-08-14
      • 2011-06-25
      • 1970-01-01
      • 2021-07-06
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      相关资源
      最近更新 更多