Reputation: 47057
I'm using the following code in my .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
# Special rewrite rules
# ideas/<id>
RewriteRule ^ideas/([0-9]+)$ idea\?id=$1
# users/<name>
RewriteRule ^users/(.+)$ users\?name=$1
The ideas/ rule works fine, as I'd expect it to, but the users/ rule doesn't seem to. It gives me a HTTP 500 error and the Apache log says it's exceeded the amount of redirects available:
[Sun Jun 14 10:58:39 2009] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://localhost/users
The url I'm testing it on is /users/ross, which should work fine. /ideas/1 definitely does work fine.
Upvotes: 0
Views: 568
Reputation: 47057
Adding a / before the files fixed this:
RewriteRule ^ideas/([0-9]+)$ ideas?id=$1
RewriteRule ^users/(.+)$ users?name=$1
to:
RewriteRule ^ideas/([0-9]+)$ /ideas?id=$1
RewriteRule ^users/(.+)$ /users?name=$1
Upvotes: 0
Reputation: 23569
Am I right to assume you've got a users.php and idea.php file? Then you can redirect to that file directly, without the need for yet another rewrite round. So, for those two rules:
RewriteRule ^ideas/([0-9]+)$ idea.php?id=$1
RewriteRule ^users/(.+)$ users.php?name=$1
(also: no need to escape the question mark in the result)
By the way: Why is users.php plural while idea.php is not? How are you handling /ideas/abc and so on?
Upvotes: 1
Reputation: 12273
What might help you to debug the situation is to make the rewrites remote (e.g. make them send HTTP redirects). This way you'll see how the requests are rewritten which should help you catch the problem.
Upvotes: 1
Reputation: 655755
Try it in this order:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteRule ^ideas/([0-9]+)$ idea?id=$1
RewriteRule ^users/(.+)$ users?name=$1
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
Upvotes: 1