Problems with rewrite/redirect rule sets

Topics: User Forum
Jul 19, 2011 at 4:31 AM

Hello everyone,

I am new to using the ISAPI Rewrite Filter and was wondering if one of you could offer some advice on using rewrite/redirect rule pairs.

I am hosting several web sites which use a content management system,  The CMS generates complex, SEO-unfriendly URLS, so I am using the ISAPI Rewrite Filter to resolve this problem.  I have successfully performed rewrites and redirects separately, but can't make them work together as the documentation suggests.

For example, here is a pair of rules I wrote for a page on my test site:

ReWriteRule ^/tournament-outings /page.php?page_id=194&name=Tournament_and_Outings

RedirectRule ^/.*(?=Tournament_and_Outings) [R=301]

The original URL is  From the first rule above you can see that I have rewritten it to an SEO-friendly URL:  The second rule redirects the old URL to the new one as recommended in the documentation.

Each of these rules will work on their own.  When the old, unfriendly URL is used, it does redirect to the new SEO-friendly URL (as shown in the address bar) but the browser displays an error message that "The page isn't redirecting properly" and that it "has detected that the server is redirecting the request for this address in a way that will never complete."

I suspect that I may be doing something wrong as I have not seen anything on this issue in the bug tracker.  Any assistance would be greatly appreciated.


Jul 19, 2011 at 12:30 PM

Right, well -

From those two rules, it looks like you may have an endless logical loop.

If someone requests http ://domain/tournament-outings, your first rule Rewrites it to the   /page.php?page_id=194&name=Tournament_and_Outings URL.   (I think what you want is for that content to actually be served by your CMS. )  Then you have a second rule, which redirects to ... the original request.  The original request gets re-submitted, then it gets rewritten, and redirected. And so on. Forever.

What you need to do is actually serve the content at the  /page.php?page_id=194&name=Tournament_and_Outings URL.  right?   So add the [L] modifier to that rewriterule.  It tells IIRF to Stop processing rules for that request. What it means is that incoming URLs like http ://domain/tournament-outings get rewritten and not redirected, whereas incoming requests like http ://domain/page.php?page_id=194&name=Tournament_and_Outings  get redirected to the simpler URL, then on re-submission get rewritten and served (not redirected).

You referred to a recommendation you found in the IIRF documentation , but you didn't provide a specific citation.  I remember writing that recommendation, but I don't remember where I wrote it.  If you could direct me to the specific location, I'd like to review it to make sure what I wrote was as clear and helpful as it could be.


Jul 19, 2011 at 5:15 PM

Hi Cheeso,

Thanks for getting back to me so quickly.

I had been wondering if the rule set would put the filter into an endless loop,but when I confirmed that the documentation contained this suggestion, I figured that it wouldn't be a problem.  The text in question is located in the Redirect v. Rewrite section of the IIRF v2.1 documentation.  It says the following:

You can use Redirect and Rewrite together

In many cases, a set of rules will include both RewriteRule directives and RedirectRule directives. For example, often rules will redirect erroneous or malformed requests to a "Not Found" page, while correctly formed requests might get rewritten on the server side.

A more typical scenario is a pair of rules that redirects and rewrites. Suppose you have a web application that has been running for some time. It uses unfriendly, non-SEO URLs, such as

  • A RedirectRule that redirects (HTTP Response 301) that non-SEO rule to the friendly URL If any external client uses the unfriendly URL, the client will be notified, via the HTTP Redirect, that the URL has changed.
  • A RewriteRule that maps from the friendly URL to the original, technology-specific URL such as

I did see some examples of the [L] modifer along with another modifer, [I] but did not find any explanation of them.  I may have missed it somewhere.  Can you tell me where this is located?

Also, I did take your suggestion and modified the rule pair as follows:

ReWriteRule ^/tournament-outings /page.php?page_id=194&name=Tournament_and_Outings [L]

RedirectRule ^/.*(?=Tournament_and_Outings) [R=301]

Everything appears to be working great now. Thanks for your assistance.



Jul 19, 2011 at 7:26 PM

Hi Ken,

the [L] modifier is documented in the page for RewriteRule.  Look for the section on modifiers.

Glad it's working now.

Also thanks for citing the section of the doc for me.  I just spent a little time updating the section of the Rewrite vs Redirect page that you cited, to give specific information on how to combine the rules, and also a reminder to use the [L] and why.  The doc will be better for the next guy.

Jul 20, 2011 at 6:07 PM

Hi Cheeso,

Thanks again for your assistance.  For the most part, the filter is working great.  I am having problems redirecting two pages, but I don't think it is a problem with your application.  It's probably just use error.  DOH!

I'm glad that I was able to help with your documentation.



Jul 9, 2012 at 9:46 AM

Hi guys

Sorry to resurrect an old post.

I'm following the exact same procedure as above, but it appears that the [L] modifier is being ignored.

ReWriteRule ^/endpage /this_highly/embedded/page.aspx [L]
RedirectRule ^/.*page\.aspx [R=301]

Based on the above rules I'm getting an endless loop in my browser.

Some advice would be greatly appreciated.