Htaccess 以某种方式自动移除 url 末尾的所有尾部斜杠,只保留一个斜杠。
例如http://localhost/api/param1///变成 http://localhost/api/param1/
你能告诉我为什么会发生这种情况以及如何摆脱这种情况吗? (.*) 应该匹配所有内容吗?但事实并非如此。就像我说的,如果我去http://localhost/api/param1/// $_GET['url']
应该是 param1///
但它是 param1/
。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
最佳答案
Apache 在 RewriteRule
模式中自动将多个斜线剥离为一个斜线。
如果您想捕获多个斜线,请改用 RewriteCond
:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ index.php?url=%1 [QSA,L]
关于php - Htaccess 重写删除尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38561645/