Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does RewriteRule ^(.*)/$ ?path=$1 [QSA,L] mean in my .htaccess?

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?

like image 519
0pTEC Avatar asked Jan 18 '26 19:01

0pTEC


1 Answers

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

  • QSA - Query String Append
  • L = Last rule

Reference: Apache mod_rewrite Introduction

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]
like image 157
anubhava Avatar answered Jan 20 '26 22:01

anubhava