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: http://thinkingmonkey.me/runs/?run=4f13665700694. 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:

1

i.e. a successful match.

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

link|improve this question

70% accept rate
1  
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 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: http://thinkingmonkey.me/runs/?run=4f13665700694. So, the RewriteCond should Match. – ThinkingMonkey Jan 16 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 at 3:31
@ShaneMadden Yes. And load the index.php instead. – ThinkingMonkey Jan 16 at 3:32
feedback

1 Answer

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]
link|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 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 at 4:21
feedback

Your Answer

 
or
required, but never shown

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