[英]Htaccess rewrite removes trailing slashes
Htaccess somehow automatically romoves all trailing slashes at the end of an url and keeps only one. Htaccess以某种方式自动地在URL的末尾删除所有尾部斜杠并且只保留一个。
For example http://localhost/api/param1/// becomes http://localhost/api/param1/ 例如, http:// localhost / api / param1 ///成为http:// localhost / api / 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/
. 就像我说的,如果我去http:// localhost / api / param1 ///
$_GET['url']
应该是param1///
但是它是param1/
。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Apache automatically strips multiple slashes into a single slash in RewriteRule
pattern. Apache会自动将多个斜杠删除为
RewriteRule
模式中的单个斜杠。
If you want to capture multiple slashes use a RewriteCond
instead: 如果要捕获多个斜杠,请使用
RewriteCond
:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ index.php?url=%1 [QSA,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.