kennycoder
kennycoder

Reputation: 56

.htaccess mod_rewrite with final slash

My .htaccess file looks like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ ?action=$1 [QSA,L]

It works allright if i end all my urls with /. For example http://localhost/test/test2/test3/. But if I forget to put / in the end, I get not found error... I've tried to tweak this rewrite rule but cant make it work both ways (with and without final /).

Any ideas?

Upvotes: 0

Views: 238

Answers (1)

Álvaro González
Álvaro González

Reputation: 146630

Make it optional with the ? operator:

RewriteRule ^(.*)/?$ foo.php?action=$1 [QSA,L] 

... or simply remove completely, since you don't seem to need it at all:

RewriteRule ^(.*)$ foo.php?action=$1 [QSA,L] 

... or even:

RewriteRule ^ foo.php?action=$0 [QSA,L] 

Upvotes: 2

Related Questions