htaccess重写删除尾部斜杠 [英] Htaccess rewrite removes trailing slashes
问题描述
Htaccess会以某种方式自动将所有结尾的斜杠移动到url的末尾,并仅保留一个斜杠。
Htaccess somehow automatically romoves all trailing slashes at the end of an url and keeps only one.
例如 http:// localhost / api / param1 //// 变为 http:// localhost / api / param1 /
您能告诉我为什么会这样以及如何摆脱吗? (。*)应该匹配所有内容吗?但事实并非如此。就像我说的,如果我转到 http:// localhost / api / param1 /// , code> $ _ GET ['url'] 应该为 param1 /// ,但应为
param1 /
。
Can you please tell me why this happens and how to get rid of this? The (.*) should match everything right? But it does not. Like I said, if I go to http://localhost/api/param1/// the $_GET['url']
should be param1///
but it is param1/
.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
推荐答案
Apache会自动使用 RewriteRule
模式将多个斜杠剥离为单个斜杠。
Apache automatically strips multiple slashes into a single slash in RewriteRule
pattern.
如果要捕获多个斜线,请使用 RewriteCond
代替:
If you want to capture multiple slashes use a RewriteCond
instead:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ index.php?url=%1 [QSA,L]
这篇关于htaccess重写删除尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!