【问题标题】:Removing multiple slashes with htaccess使用 htaccess 删除多个斜杠
【发布时间】:2013-12-03 14:23:51
【问题描述】:

我知道如何用 PHP 做到这一点,如何将 URL 中的多个斜杠替换为一个,例如:

http://example.com/uri1////////uri2/uri4

替换为:

http://example.com/uri1/uri2/uri4

等等。用 htaccess 怎么办?

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s[^?]*//
    RewriteRule ^.*$ /$0 [R=301,L,NE]
    

    【讨论】:

    • 它很好,但它将全部替换为两个斜杠,例如。 http://address.com////////////////////////urihttp://address.com//uri
    猜你喜欢
    • 2012-08-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2016-01-03
    • 2015-01-15
    • 1970-01-01
    相关资源
    最近更新 更多