Prakash Raman
Prakash Raman

Reputation: 13943

Possibly two rewrite being matched in my htaccess

I would like to rewrite the following 2 URLs to 2 different pages

/potato/prakash.raman ----> /potato/user.php?handle=prakash.raman
/potato/prakash.raman/watchlist ----> /potato/watchlist.php?handle=prakash.raman

These are my rewrites

ReWriteRule ^(.*)/watchlist watchlist.php?handle=$1
ReWriteRule ^(.*)$ user.php?handle=$1

Both seem to getting rewritten to user.php?handle

What could I be doing wrong. How can I fix this ?

Upvotes: 0

Views: 36

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270697

Add RewriteCond to guard against rewriting existing files, and add the [L] flag to ensure no further rules are matched after the first match:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ReWriteRule ^(.*)/watchlist watchlist.php?handle=$1 [L]
ReWriteRule ^(.*)$ user.php?handle=$1 [L]

Upvotes: 1

Related Questions