Hi all, need some assistance on a rule.
Scenario: web server once had an old content management system that is no longer in use. Outside site links to some old web pages that are related to the CMS and no longer exist (links cannot be changed). I'm trying to redirect them to new pages.
old page : www.example.com/old/start.taf?page=old_page
new page: www.example.com/new_page
Here is my IsapiRewrite4.ini:
RewriteRule ^/old/start.taf?page=old_page /new_page [R]
When I go to www.example.com/old/start.taf?page=old_page I receive a page cannot be found.
In the log file:
ReadConfig: setting LogLevel to 5
ReadConfig: line 3: RewriteRule 1 ^/old/start.taf?page=old_page /new_page
ReadConfig: not a duplicate rule...
ParseRuleModifierFlags: token 'R'
ReadConfig: Done reading, found 1 rules (0 failed) on 4 lines
Initialize: Ionic ISAPI Rewriting Filter (IIRF) v1.2.14 final R2
Initialize: config file 'C:\WINDOWS\system32\inetsrv\iirf\IsapiRewrite4.ini'
Initialize: main threadId= 3368
Initialize: File watcher thread created.
FileChangeWatcher(): Enter, threadId=3576...
OnUrlMap: storing physical path (D:\webroot\old\start.taf), in ptr (0x000c56b0)
GetServerVariable_AutoFree: getting 'url'
GetServerVariable_AutoFree - no joy (GetLastError()=1413)
GetServerVariable_AutoFree: 128 bytes
GetServerVariable_AutoFree: result ''
GetHeader_AutoFree: getting 'url'
GetHeader_AutoFree: 37 bytes
GetHeader_AutoFree: result '/old/start.taf?page=old_page'
GetServerVariable_AutoFree: getting 'QUERY_STRING'
GetServerVariable_AutoFree: 18 bytes
GetServerVariable_AutoFree: result 'page=old_page'
GetHeader_AutoFree: getting 'method'
GetHeader_AutoFree: 4 bytes
GetHeader_AutoFree: result 'GET'
DoRewrites: New Url: '/old/start.taf?page=old_page'
ApplyRules: Rule 1 : -1 (No match)
ApplyRules: returning 0
DoRewrites: No Rewrite
Am I missing something?
Thanks in advance!
Aug 8, 2008 at 5:05 AM
IIRF can do what you want to do, but you have to be savvy of the regular expression (regex) syntax.
Regex is what you use to specify the pattern to match. Inside the regex language, the question mark ? is meaningful. A question mark in the pattern does not match a question mark in the request.
If you want to match a question mark, as apparently you do, then you need to "escape" the question mark in your pattern. Like so:
RewriteRule ^/old/start.taf\?page=old_page /new_page [R]
Also, if the URL is never coming back, I would recommend R=301 as the redirect flag. 301 implies "Moved Permanently" whereas the default [R] indicates "Moved Temporarily".
Therefore the final result is
RewriteRule ^/old/start.taf\?page=old_page /new_page [R=301]