Htaccess RewriteRule override issue


I’ve created a RewriteRule like below.

RewriteRule ^book/(\w+)/? contentpages/book/book.php?thing_id=$1 [NC,L]

I also need to create a clean tag url, but when I try the rule below, it doesn’t work because of the previous rule (probably), how can I fix this issue?

RewriteRule ^book/tag/(\w+)/? contentpages/book/tag.php?tag_value=$1 [NC,L]**

Both rules should use an end anchor.


1 Like

It worked, thank you!

I have a new issue that I couldn’t solve. I’m trying to pass two parameters, how can I do it?

My current rules (separate)

RewriteRule ^book/(\w+)/?$ contentpages/book/book.php?thing_id=$1 [NC,L] // $_GET['thing_id'] works
RewriteRule ^book/tag/(\w+)/?$ contentpages/book/tag.php?tag_value=$1 [NC,L] // $_GET['tag_value'] works

But I want two of them in one url, like so : book/6/tag/great

I created the rule below, but it doesn’t work when I use book url, book4 or some random name like book5 works.

RewriteRule ^book4/(\w+)/tag/(\w+)/?$ contentpages/book/tag.php?tag_value=$1&thing_id=$2

I want to be able to get both tag and thing_id using a single rule and echo them in my tag.php file using $_GET requests.

EDIT : Okay, I solved it. Another rule was overriding this one. I’m leaving the message as it is since it may help other people in the future.


BOTH RewriteRules should NOT have the optional trailing slash as that would suggest to the server that the visitor is requesting a directory. Worse, relative links don’t know which directory level they’re supposed to retrieve internally linked files from. Test your code using the trailing / as well as without and you’ll see the problem (missing support files).



This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.