开发者

Apache Rewrite Question: Similar url patterns

开发者 https://www.devze.com 2023-02-18 19:14 出处:网络
I am trying to tidy up the urls on my site. I have written the followin开发者_开发技巧g rules. For

I am trying to tidy up the urls on my site. I have written the followin开发者_开发技巧g 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


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消