Thread7
Thread7

Reputation: 1090

.htaccess rule gives 500 error for php file

I saw another stackoverflow answer to come up with this current setup. I want requests to http://myserver.com/book/1234 to actually show the content from php file http://myserver.com/book.php?id=1234

So my .htaccess looks like this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^book/(.*)$ /book.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

Notice the bottom two lines allow me to use url's like http://myserver.php/login to actually pull up http://myserver.php/login.php This is working correctly. But I get a 500 Error when I try calling http://myserver.com/book/1234 What is wrong?

Upvotes: 1

Views: 75

Answers (1)

Mike Rockétt
Mike Rockétt

Reputation: 9007

Your code is instructing the server to only do the rewrite if the query string is present. As a result, the rule would only work if you requested /book/1234?id=1234.

Removing the line below will allow your rewrite to work.

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$

Upvotes: 1

Related Questions