Trouble with 2 RewriteRule

I have a trouble with two Rewriterule in my htaccess

RewriteRule ^(.)/(.)/(.*)/([0-9]+)/?$ viewauthor.php?lg=$1&cat=$2&nameauthor=$3&id=$4 [NC,L]

RewriteRule ^(.)/(.)/(.*)/([0-9]+)/?$ viewbook.php?lg=$1&cat=$2&namebook=$3&id=$4 [NC,L]

I can't access to the second rewriterule cause it's similar.

to see which page I am on. I put echo $SERVER['QUERYSTRING']; in those two page.

When I remove the flag [NC,L], I access to the second rewriterule but the lg=viewauthor.php instead lg=en.

Thanks for help

2 Replies

The second rule won't be processed when [NC,L] is present on the first rule because [L] tells Apache "this is the last rule; stop processing after this test and return the result". So if the URL matches the regex on the first rule, it does the substitution and immediately returns. The second rule will never be processed.

That said, I don't think the second rule does what you think it's supposed to do. You're using the same regex for both rules. I think you're getting "lg=viewauthor.php" because it's performing the substitution in the first rule, then running it back through the second rule and substituting again. I get the feeling this isn't what you really want. Unfortunately, I don't know exactly what your use case is supposed to be here, so it's hard to offer suggestions for a fix. It looks like you're trying to create a transparent "pretty" URL that passes parameters to an "ugly" PHP call, kind of like what MediaWiki does. (I do something similar on my site with archive URLs.) You might want to differentiate authors and books with something unique in the "pretty" URL, like this:

RewriteRule ^/authors/(.*)/(.*)/(.*)/([0-9]+)/?$ viewauthor.php?lg=$1&cat=$2&nameauthor=$3&id=$4 [NC,L]
RewriteRule ^/books/(.*)/(.*)/(.*)/([0-9]+)/?$ viewbook.php?lg=$1&cat=$2&namebook=$3&id=$4 [NC,L]


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct