Trouble getting RedirectRule to work SOLVED (need to escape the ?)

Topics: User Forum
Sep 5, 2011 at 2:35 AM

Firstly, thank you for this remarkable tool. This is going to significantly make our URLs cleaner for both public and search engine consumption.

I've been able to successfully setup a RewriteRule to mask the ugly CMS URL to a friendly one:

  • Friendly version: /services/library
  • CMS version: /page.aspx?pid=144&vid=11

I'm using the following rule:

RewriteRule ^(/services/library)+(/?)$ /page.aspx?pid=144&vid=11 [I,L]

This is working great.

Now I'd like to replace the URL in the browser's address bar for the original ugly CMS URL by redirecting the request, just in case people are still using the old address. I'm using the method outlined in "You can use Redirect and Rewrite together" and have added this to the previous rule.

RedirectRule ^/page.aspx?pid=144&vid=11$    http://webstager/services/libraries [R=301]
RewriteRule ^(/services/library)+(/?)$    /page.aspx?pid=144&vid=11 [I,L]

While the RewriteRule is still working fine, my RedirectRule isn't. The page still appears fine, it just seems that the redirect isn't occurring (or at least the web address is still the ugly version). What am I missing here?

Originally I didn't add the "http://webstager" to the redirect and was receiving an error in the log file, even though I only want to redirect to a local page. The error has disappeared now.

I've tried changing the order of the rules around, moved the [L] modifier between rules. I've been reading through the discussion forums and documentation for hours - I'm just not sure what I'm doing wrong here.

Sep 5, 2011 at 2:58 AM

I've copied the relevant lines from the log file. If you need anything else I can supply the entire file. Looking at the log, it's clear the it's just not matching the URL in order to perform the redirect, I'm just not sure why.

Do I need to escape ampersands (&)?

Mon Sep 05 11:52:30 -  4648 - DoRewrites: Url (decoded): '/page.aspx?pid=144&vid=11'
Mon Sep 05 11:52:30 -  4648 - EvaluateRules: depth=0
Mon Sep 05 11:52:30 -  4648 - EvaluateRules: no RewriteBase
Mon Sep 05 11:52:30 -  4648 - EvaluateRules: Rule 1: -1 (No match)
Mon Sep 05 11:52:30 -  4648 - EvaluateRules: Rule 2: -1 (No match)
Mon Sep 05 11:52:30 -  4648 - EvaluateRules: Rule 3: -1 (No match)
Mon Sep 05 11:52:30 -  4648 - EvaluateRules: Rule 4: -1 (No match)
Mon Sep 05 11:52:30 -  4648 - EvaluateRules: returning 0
Mon Sep 05 11:52:30 -  4648 - DoRewrites: No Rewrite
Mon Sep 05 11:52:30 -  4648 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Sep 05 11:52:30 -  4648 - HttpFilterProc: cfg= 0x01CB5B78
Mon Sep 05 11:52:30 -  4560 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Sep 05 11:52:30 -  4560 - HttpFilterProc: cfg= 0x01CB5B78
Mon Sep 05 11:52:30 -  5664 - HttpFilterProc: SF_NOTIFY_URL_MAP
Mon Sep 05 11:52:30 -  5664 - HttpFilterProc: cfg= 0x01CB5B78
Mon Sep 05 11:52:30 -  5664 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE

Sep 5, 2011 at 3:08 AM

Finally worked it out - I can't believe it took me so long!

RedirectRule ^/page.aspx\?pid=144&vid=11$ http://webstager/services/library [R=301]
RewriteRule ^(/services/library)+(/?)$ /page.aspx?pid=144&vid=11 [I,L]

As soon as I escaped the ? character in the regular expression, I got it working - shown in bold above.

Thanks anyway - hopefully this post will prove useful to other people :)