Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Htaccess rewrite removes trailing slashes

Tags:

php

.htaccess

Htaccess somehow automatically romoves all trailing slashes at the end of an url and keeps only one.

For example http://localhost/api/param1/// becomes 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/.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
like image 845
miXo Avatar asked Oct 19 '22 05:10

miXo


1 Answers

Apache automatically strips multiple slashes into a single slash in RewriteRule pattern.

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]
like image 83
anubhava Avatar answered Oct 24 '22 13:10

anubhava