Trouble with recursion

Topics: Developer Forum, User Forum
Feb 17, 2010 at 7:12 PM
Edited Feb 17, 2010 at 10:40 PM

I have the following directives:

RewriteCond %{URL} /FAQ\.html    [I]
RewriteRule .* /f-a-q.html

RewriteCond  %{URL} ([\w\-]*).html$
RewriteRule ([\w\-]*).html$ /index.php?seo_name=$1

Testing two sample URLs with testdriver results in the following:

REWRITE '' ==> '/f-a-q.html'
REWRITE '' ==> '/index.php?seo_name=f-a-q'

I was expecting /FAQ.html to be rewritten to /f-a-q.html by the first directive, and then rewritten to /index.php?seo_name=f-a-q by the second directive.  However, the results of testdriver show this isn't working.

I'll bet this is a problem with my regex, or possibly with my use of ${URL} in the second directive, but I can't seem to work out the problem.  Can anyone explain to me why this isn't working?  Thanks!

by the second directive
Feb 17, 2010 at 9:32 PM
Edited Feb 18, 2010 at 12:42 AM

I don't know why it's not working, but it could be because the server variables are not active within the context of the testdriver.   This is a known limitation of the testdriver.  Aside from that, i suggest you avoid the use of %{URL} in the RewriteCond.  The URL is the thing that the RewriteRule tests, implicitly.  So your rules that combine a RewriteCond (using URL) and a RewriteRule are unnecessarily complicated.  They can be written more cleanly using a single RewriteRule, with no external condition, like so:

RewriteRule ^/FAQ.html$ /f-a-q.html
RewriteRule ^/([\w\-]*).html$ /index.php?seo_name=$1
Feb 17, 2010 at 10:40 PM

Awesome!  Not only does that simplify my entire rewrite file (which was much larger than the sample I provided), but it got the recursion working properly.  Thanks so much for your quick reply and a fantastic product. =)

Mar 4, 2010 at 3:16 PM

Sure thing, I'm glad to help.  Thanks for the compliments.  Good luck!