Rewrite URL: Internal Server Error

I have a little problem with Apache rewrite rules

Here are my rules

Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule query/(.*) /php/query.php?name=$1 [L] RewriteRule page/(.*) /php/page.php?page=$1 [L] 

It works great. But when I try to add the following rule to rewrite a URL that does not match the two previous rules

 RewriteRule .* /php/page.php?page=home 

The server responds with "Internal Server Error". Why?

+1
url-rewriting apache mod-rewrite
source share
2 answers

You can use RewriteLog to find out what is happening, but even with [L] you can be sure that the rewritten URL is always cross-checked by a set of rules (this is an internal call forwarding).

So, add a little RewriteCond before this final catch-all or don't include it in the internal redirects, like this:

 RewriteCond %{ENV:REDIRECT_STATUS} ^$ 

You can also add the [NS] or [nosubreq] to your latest catch-all file, which does the same.

But preventing your rule from being redirected internally also means that it will never be applied after any previous rule, and one day you may need it. Therefore, be careful with the following rules.

+4
source share

Thanks!

Finally, here is my solution:

 Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule query/(.*) /php/query.php?name=$1 [L] RewriteRule page/(.*) /php/page.php?page=$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ page/home [L,R] RewriteRule ^$ page/home [NS,R] 
0
source share

All Articles