Htaccess重写删除尾部斜杠

miX*_*iXo 5 php .htaccess

Htaccess以某种方式自动地在URL的末尾删除所有尾部斜杠并且只保留一个.

例如,http:// localhost/api/param1 ///成为http:// localhost/api/param1 /

你能否告诉我为什么会发生这种情况以及如何摆脱这种情况?(.*)应该匹配一切吗?但事实并非如此.就像我说的,如果我去的http://本地主机/ API /参数1 ///$_GET['url']应该是param1///,但它是param1/.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

anu*_*ava 3

Apache 会自动将多个斜杠剥离为模式中的单个斜杠RewriteRule

如果你想捕获多个斜杠,请使用 aRewriteCond代替:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ index.php?url=%1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)