guy777
guy777

Reputation: 242

URL rewrite : internal server error

I have a little problem on Apache's rewrite rules

Here's 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 perfectly. But when I try to add the following rule to rewrite URL that not matches the two previous rules

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

The server responds "Internal server error". Why ?

Upvotes: 1

Views: 847

Answers (2)

guy777
guy777

Reputation: 242

Thanks !

Finally, here's 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]

Upvotes: 0

regilero
regilero

Reputation: 30496

You can use RewriteLog to see what happends, but even with a [L] you can be sure a rewrited url is always re-checked on the set of rules (this is call internal redirect).

So add some RewriteCond before this final catch-all, or prevent it to be running on internal redirects, this way:

RewriteCond %{ENV:REDIRECT_STATUS} ^$

You could also add the [NS] or [nosubreq] tag on your final catch-all, which does the same.

But preventing your rule on internal redirection also means it will never be applied after any previous rule, and one day you might want it. So be careful with next rules.

Upvotes: 4

Related Questions