I'm currently creating a webpage which requires rewrites to look nice.

The URL is: u.{my_site}/get.php?fid={ID}.

The URL entered should be: u.{my_site}/{ID}.

Because I'm bad (and new) at rewrite regexes, I generated the following code:

RewriteEngine On
RewriteRule ^([^/]*)$ /get.php?fid=$1 [L]

Now when I try to open u.{my_site}/{ID}, it returns a 500 error and the logs state:

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.

What is causing this error and how can it be fixed?


Found out that the generator doesn't generate RewriteCond, so now it redirects on every page (including /get.php).

  • "the generator"? You're correct, you'll need a RewriteCond directive to prevent requests for /get.php being rewritten - this is what's causing your internal redirect loop.
    – MrWhite
    Commented Nov 15, 2013 at 23:57

2 Answers 2


As mentioned in comments above, you'll need a RewriteCond directive in order to prevent an internal rewrite loop. Whilst the L flag terminates the current rule set, the entire process is started again with the rewritten URL, so we need a get-out clause.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !^fid=
RewriteRule ^([^/]*)$ /get.php?fid=$1 [L]

The 2nd %{QUERY_STRING} line prevents a rewrite loop by not rewriting if the query string is already present.

The 1st %{REQUEST_FILENAME} line prevents redirection if an existing file is requested. This is quite common when implementing "pretty" URLs, so you can request an arbitrary file if required. (As it happens this also prevents get.php being rewritten.)

Just to note, your pattern ^([^/]*)$ will not match URLs that contain a slash - there will be no match and the URL will not be rewritten. This may be desirable in your situation. However, if you wanted to match everything upto the first slash, or the entire string (if no slashes are found), then remove the end of string placeholder ($).


I actually found out (with the help of a friend) that

RewriteRule ^([a-zA-Z0-9]{3})$ get.php?fid=$1 [PT]

Is sufficient.

Please do comment when this statement contains any traps or security issues.

  • That looks good to me. You've restricted the {ID} to 3 characters (from being pretty much anything). Your substitution is obviously more than 3 chars, so no loop. However, I would query the use of the PT flag though - it seems unnecessary IMO.
    – MrWhite
    Commented Nov 18, 2013 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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