Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is what I have in my .htaccess file.

RewriteEngine on

RewriteCond %{QUERY_STRING}  ^(run=[a-z0-9A-z]{13})$
RewriteRule %{QUERY_STRING}  \? [L]

All I am doing is Rewriting the QUERY_STRING for all QUERY_STRING similar to run=4f13665700694 and do nothing. A URL example: So, the RewriteCond should Match. But the above does not work.

But, the pattern seemed correct. Since, both preg_match & RewriteRule use PCRE - Perl Compatible Regular Expressions.

I tried it using preg_match.

$subject = "run=4f13665700694"; 
$pattern = "/^(run=[a-z0-9A-z]{13})$/";

echo preg_match($pattern, $subject);

And as excepted the above will output:


i.e. a successful match.

I do not understand why. What am I missing here?

share|improve this question
Your RewriteCond should match, but you'll have to clarify what you're going after with that RewriteRule, as it won't work as written. – Shane Madden Jan 16 '12 at 3:14
@ShaneMadden I am trying to remove the run=.. part and just redirect the URL to the index there. The URL looks like this: So, the RewriteCond should Match. – ThinkingMonkey Jan 16 '12 at 3:28
So, you're trying to maintain the current URL exactly, except strip the query string? Is that correct? – Shane Madden Jan 16 '12 at 3:31
@ShaneMadden Yes. And load the index.php instead. – ThinkingMonkey Jan 16 '12 at 3:32
up vote 1 down vote accepted

Ok, so, this will take a request to /runs/ with the 13-character alphanumeric run parameter as the only thing in its query string, strip the query string, and rewrite to /runs/index.php:

RewriteCond %{QUERY_STRING} ^run=\w{13}$
RewriteRule ^/runs/?$ /runs/index.php? [L]
share|improve this answer
what does the w in ^run=\w{13}$ stand for? and I cannot use %{QUERY_STRING} in a RewriteRule? – ThinkingMonkey Jan 16 '12 at 3:51
what does the w in ^run=\w{13}$ stand for? Equivalent to what you had, except it adds _. and I cannot use %{QUERY_STRING} in a RewriteRule? The place where you had it is the URL pattern, not the string that you're checking; the argument order isn't the same as RewriteCond. – Shane Madden Jan 16 '12 at 4:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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