I am trying to tidy up the urls on my site. I have written the following rules. For

index.php?id=work&pid=work-item 
RewriteRule (.*)/(.*)/$ /index.php?id=$1&pid=$2 [L]

Which works and looks like this:

 /work/work-item/

Then for:

index.php?id=work&tag=1
RewriteRule (.*)/(.*)/$ /index.php?id=$1&tag=$2 [L]

Which also works but breaks the first rule. Does anyone have any ideas for a solution.

Thanks,

Joe

Accepted Answer

Yes, you need to add a RewriteCond in order to make the rewrite rule conditional and not apply to anything that matches your regex.

RewriteCond %{QUERY_STRING} ^pid=...$
RewriteRule (.*)/(.*)/$ /index.php?id=$1&pid=$2 [L]

and

RewriteCond %{QUERY_STRING} ^tag=...$
RewriteRule (.*)/(.*)/$ /index.php?id=$1&tag=$2 [L]
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki