Reputation: 53
I need to create rewrite in nginx as is done in my .htaccess and there are some lines which I don't completely understand.
DirectoryIndex index.php
RewriteEngine on
RewriteCond % !-f
RewriteRule ^(.*)/$ ?path=$1 [QSA,L]
Can someone explain it to me?
Upvotes: 3
Views: 15838
Reputation: 785196
RewriteCond % !-f
seems incorrect rule condition and is always evaluating to true.
This rule:
RewriteRule ^(.*)/$ ?path=$1 [QSA,L]
Is matching any URI with trailing slash and internally rewriting to /?path=uri-without-slash
So for ex: an URI /foo/
will be rewritten to /?path=foo
UPDATE: Change that incorrect condition to:
# request is not for a file
RewriteCond %{REQUEST_FILENAME} !-f
# request is not for a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ ?path=$1 [QSA,L]
Upvotes: 7
Reputation: 490263
It means if the request isn't to a file, then rewrite everything before a trailing /
into index.php?path=
followed by what was previously matched.
It should be the last rule (L
) and it should append the query string (QSA
), as opposed to discarding it because of the replacement's query string.
Upvotes: 1