how to remove multiple slashes in URI with 'PREG' or 'HTACCESS'

后端 未结 5 2122
滥情空心
滥情空心 2021-01-04 21:51

how to remove multiple slashes in URI with \'PREG\' or \'HTACCESS\'

site.com/edition/new/// -> site.com/edition/new/


site.com/edition///new/ -> site.co

5条回答
  •  失恋的感觉
    2021-01-04 22:30

    http://domain.com/test/test/ > http://domain.com/test/test

    # Strip trailing slash(es) from uri
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+?)[/]+$ $1 [NC,R,L]
    

    http://domain.com//test//test// > http://domain.com/test/test/

    # Merge multiple slashes in uri
    RewriteCond %{THE_REQUEST} ^[A-Z]+\ //*(.+)//+(.*)\ HTTP
    RewriteRule ^ /%1/%2 [R,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]+\ //+(.*)\ HTTP
    RewriteRule ^ /%1 [R,L]
    

    Change R to R=301 if everything works fine after testing...

    Does anyone know how to preserve double slashes in query using above method?

    (For example: /test//test//?test=test//test > /test/test/?test=test//test)

提交回复
热议问题