On my local WAMP server the following lines in .htaccess cause no problems, and do what I want:

RewriteEngine On
Options FollowSymLinks
RewriteRule ^foo/([0-9]+)/[a-z0-9-]*?$ foo.php?id=$1 [L]

When I upload this to my hosted (LAMP) site it causes a 500 error (regardless of whether the rewriterule comes in to play or not). After much tinkering, the fix was to make remove the unhungry/lazy modifier to the regex, i.e.:

RewriteEngine On
Options FollowSymLinks
RewriteRule ^foo/([0-9]+)/[a-z0-9-]*$ foo.php?id=$1 [L]

Now, in the case I've presented it's arguable whether the difference in the regex serves any purpose, but still to my mind the first example is valid, and it did work on my local WAMP server. So does anyone have a clear idea why I got the 500 error?


Add slash before foo.php:

RewriteRule ^foo/([0-9]+)/[a-z0-9-]*?$ /foo.php?id=$1 [L]

or move rewrite rules from virtual host config to .htaccess.

  • Interesting. Will give that a go. But how does that conflict with using the question-mark quantifier? – beldaz Jan 31 '11 at 11:53
  • Both rulues not supported(with and without question-mark quantifier) in httpd.conf – alvosu Jan 31 '11 at 12:06
  • Ah. But in the example I am already using .htaccess, and the rule without the question mark quantifier already works. So I don't think the solves my particular problem. – beldaz Feb 1 '11 at 11:36
  • Debian Sid , Apache 2.2.16-6... your rules(with and without quantifier already) work in .htacces. You don't write than use .htacces in LAMP. – alvosu Feb 1 '11 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.