Rewrite all pages using these rules

Topics: Developer Forum, Project Management Forum, User Forum
Aug 4, 2009 at 3:08 PM

Hi,

I'd like to use the ionics isapi rewrite filter to perform the following:

rewrite www.foo.com/default.aspx  to www.foo.com

rewite all other pages e.g www.foo.com/login.aspx to www.foo.com/login

or

 www.foo.com/anotherpage.aspx to www.foo.com/anotherpage

e.t.c

can this be done? if so, please can someone tell me how. 

thanks

shane

Coordinator
Aug 4, 2009 at 8:43 PM

oh yes, it can be done!  very easily!

Just read the fine manual and you'll learn how, very quickly.  There are lots of good examples. 

 

Aug 4, 2009 at 8:52 PM

hi,

i started reading the manual and realised I had to resolve another issue first namely how do I configure iis for visual studio 2008 whcih i use on for development on my laptop as this is required to install the filter.  I'd rather do this first before going "online", configuraiton of iis does not seem to appear in the vs2008 ide. strange!

Coordinator
Aug 4, 2009 at 9:33 PM

That's right - there's no reason to use the filter unless you have IIS.

Aug 4, 2009 at 11:55 PM
Cheeso wrote:

That's right - there's no reason to use the filter unless you have IIS.

ok.

I have now installed the filter on a staging server (running IIS) and used the most basic rewrite rule as follows:

RewriteRule ^/alogin  /aLogin.aspx

the rewrite does not occur i.e the page does not load or at least is not found.  logging file says -1 (no match)

looks like I am missing something simple

Coordinator
Aug 5, 2009 at 2:50 AM

Well if there are logging messages then you know that you have the filter loaded properly.

In the log before it says "-1 no match" it should list the incoming URL, and other interesting information.  By reviewing that you should be able to figure out why it is not matching.

If you want you can post the log file and I'll look at it here.

Aug 5, 2009 at 4:17 AM
Edited Aug 5, 2009 at 4:46 AM

sure, here is an extract of the log file

Wed Aug 05 02:23:14 -  1260 - DllMain THREAD_DETACH
Wed Aug 05 02:23:24 -  3520 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Aug 05 02:23:24 -  3520 - OnUrlMap: storing physical path (c:\inetpub\wwwroot\0.4\aLogin), 37 bytes, in ptr (0x0011b708)
Wed Aug 05 02:23:24 -  3520 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Aug 05 02:23:24 -  3520 - DoRewrites
Wed Aug 05 02:23:24 -  3520 - GetServerVariable_AutoFree: getting 'url'
Wed Aug 05 02:23:24 -  3520 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Aug 05 02:23:24 -  3520 - GetServerVariable_AutoFree: 128 bytes
Wed Aug 05 02:23:24 -  3520 - GetServerVariable_AutoFree: result ''
Wed Aug 05 02:23:24 -  3520 - GetHeader_AutoFree: getting 'url'
Wed Aug 05 02:23:24 -  3520 - GetHeader_AutoFree: 19 bytes   ptr:0x000C3520
Wed Aug 05 02:23:24 -  3520 - GetHeader_AutoFree: 'url' = '/0.4/aLogin'
Wed Aug 05 02:23:24 -  3520 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
Wed Aug 05 02:23:24 -  3520 - GetServerVariable_AutoFree: 1 bytes
Wed Aug 05 02:23:24 -  3520 - GetServerVariable_AutoFree: result ''
Wed Aug 05 02:23:24 -  3520 - GetHeader_AutoFree: getting 'method'
Wed Aug 05 02:23:24 -  3520 - GetHeader_AutoFree: 4 bytes   ptr:0x000C3650
Wed Aug 05 02:23:24 -  3520 - GetHeader_AutoFree: 'method' = 'GET'
Wed Aug 05 02:23:24 -  3520 - DoRewrites: Url: '/0.4/aLogin'
Wed Aug 05 02:23:24 -  3520 - EvaluateRules: depth=0
Wed Aug 05 02:23:24 -  3520 - EvaluateRules: Rule 1 : -1 (No match)
Wed Aug 05 02:23:24 -  3520 - EvaluateRules: returning 0
Wed Aug 05 02:23:24 -  3520 - DoRewrites: No Rewrite
Wed Aug 05 02:23:26 -  3520 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Aug 05 02:23:26 -  3520 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Aug 05 02:23:26 -  3520 - DoRewrites
Wed Aug 05 02:23:26 -  3520 - GetServerVariable_AutoFree: getting 'url'
Wed Aug 05 02:23:26 -  3520 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Aug 05 02:23:26 -  3520 - GetServerVariable_AutoFree: 128 bytes
Wed Aug 05 02:23:26 -  3520 - GetServerVariable_AutoFree: result ''
Wed Aug 05 02:23:26 -  3520 - GetHeader_AutoFree: getting 'url'
Wed Aug 05 02:23:26 -  3520 - GetHeader_AutoFree: 19 bytes   ptr:0x000CCE70
Wed Aug 05 02:23:26 -  3520 - GetHeader_AutoFree: 'url' = '/0.4/aLogin'
Wed Aug 05 02:23:26 -  3520 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
Wed Aug 05 02:23:26 -  3520 - GetServerVariable_AutoFree: 1 bytes
Wed Aug 05 02:23:26 -  3520 - GetServerVariable_AutoFree: result ''
Wed Aug 05 02:23:26 -  3520 - GetHeader_AutoFree: getting 'method'
Wed Aug 05 02:23:26 -  3520 - GetHeader_AutoFree: 4 bytes   ptr:0x000CC410
Wed Aug 05 02:23:26 -  3520 - GetHeader_AutoFree: 'method' = 'GET'
Wed Aug 05 02:23:26 -  3520 - DoRewrites: Url: '/0.4/aLogin'
Wed Aug 05 02:23:26 -  3520 - EvaluateRules: depth=0
Wed Aug 05 02:23:26 -  3520 - EvaluateRules: Rule 1 : -1 (No match)
Wed Aug 05 02:23:26 -  3520 - EvaluateRules: returning 0
Wed Aug 05 02:23:26 -  3520 - DoRewrites: No Rewrite
Wed Aug 05 02:23:27 -  3520 - HttpFilterProc: SF_NOTIFY_URL_MAP

 

tn x for looking at it :)

UPDATE

I've also tried this rule with the no luck either

RewriteRule ^/([^/\.]+)$ /$1.aspx [L]

 


--------------------------------------------
Wed Aug 05 05:24:55 -   368 - ReadConfig: setting LogLevel to 5
Wed Aug 05 05:24:55 -   368 - ReadConfig: line  12: RewriteRule (rule 1)  '^/([^/\.]+)$'  '/$1.aspx'      [L]
Wed Aug 05 05:24:55 -   368 - ReadConfig: not a duplicate rule...
Wed Aug 05 05:24:55 -   368 - ParseRuleModifierFlags: '[L]'
Wed Aug 05 05:24:55 -   368 - ParseRuleModifierFlags: token 'L'
Wed Aug 05 05:24:55 -   368 - rule: Last
Wed Aug 05 05:24:55 -   368 - ReadConfig: Done reading, found 1 rules (0 errors, 1 warnings) on 16 lines

--------------------------------------------
Wed Aug 05 05:24:55 -   368 - Initialize: Ionic ISAPI Rewriting Filter (IIRF) v1.2.16 R6
Wed Aug 05 05:24:55 -   368 - Initialize: config file 'C:\IIRF\04\IsapiRewrite4.ini'
Wed Aug 05 05:24:55 -   368 - Initialize: File watcher thread created.
Wed Aug 05 05:24:55 -   368 - GetFilterVersion
Wed Aug 05 05:24:55 -  1720 - FileChangeWatcher(): Enter
Wed Aug 05 05:24:55 -  1720 - FileChangeWatcher: Await()...
Wed Aug 05 05:24:55 -  1720 - AwaitIniChangeAndReinit()...
Wed Aug 05 05:24:55 -   368 - HttpFilterProc: SF_NOTIFY_URL_MAP
Wed Aug 05 05:24:55 -   368 - OnUrlMap: storing physical path (c:\inetpub\wwwroot\0.4\Default.aspx), 43 bytes, in ptr (0x000b4eb0)
Wed Aug 05 05:24:55 -   368 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Wed Aug 05 05:24:55 -   368 - DoRewrites
Wed Aug 05 05:24:55 -   368 - GetServerVariable_AutoFree: getting 'url'
Wed Aug 05 05:24:55 -   368 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Aug 05 05:24:55 -   368 - GetServerVariable_AutoFree: 128 bytes
Wed Aug 05 05:24:55 -   368 - GetServerVariable_AutoFree: result ''
Wed Aug 05 05:24:55 -   368 - GetHeader_AutoFree: getting 'url'
Wed Aug 05 05:24:55 -   368 - GetHeader_AutoFree: 25 bytes   ptr:0x000CC708
Wed Aug 05 05:24:55 -   368 - GetHeader_AutoFree: 'url' = '/0.4/Default.aspx'
Wed Aug 05 05:24:55 -   368 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
Wed Aug 05 05:24:55 -   368 - GetServerVariable_AutoFree: 1 bytes
Wed Aug 05 05:24:55 -   368 - GetServerVariable_AutoFree: result ''
Wed Aug 05 05:24:55 -   368 - GetHeader_AutoFree: getting 'method'
Wed Aug 05 05:24:55 -   368 - GetHeader_AutoFree: 4 bytes   ptr:0x000CC840
Wed Aug 05 05:24:55 -   368 - GetHeader_AutoFree: 'method' = 'GET'
Wed Aug 05 05:24:55 -   368 - DoRewrites: Url: '/0.4/Default.aspx'
Wed Aug 05 05:24:55 -   368 - EvaluateRules: depth=0
Wed Aug 05 05:24:55 -   368 - EvaluateRules: Rule 1 : -1 (No match)
Wed Aug 05 05:24:55 -   368 - EvaluateRules: returning 0
Wed Aug 05 05:24:55 -   368 - DoRewrites: No Rewrite
Wed Aug 05 05:24:55 -   368 - HttpFilterProc: SF_NOTIFY_URL_MAP

 

Aug 5, 2009 at 7:44 AM

now we are cooking!

it was a simple thing really, because there are multiple domains representing versions (i.e 0.4) it has to be included in the rewrite rule as shown below:

RewriteRule ^/0.4/alogin  /0.4/aLogin.aspx

i guess this would apply for the more advanced rule as well so it would become:

RewriteRule ^/0.4/([^/\.]+)$ /$1.aspx [L]

now i need to think of every scenairo and write a more robust rule with rewrites and no rewrites

in particular the advanced rule would map rewrite foo.com/default to foo.com/default.aspx which is not a good idea

i'm startng to enjoy this now!

tnx for your help.....

 

Coordinator
Aug 5, 2009 at 9:24 AM

well good, i'm glad you are figuring it out.

let me know if you have more questions.

 

Aug 5, 2009 at 6:16 PM
Edited Aug 5, 2009 at 6:19 PM

hmm! hello again

i'm stuck on how to force foo.com to always point to foo.com/default.aspx :

^/0.4/ /0.4/default.aspx

it's the first rule and it just messes up all the links on the site

also this rule must not affecting another rule that says remove all .aspx extension so that foo.com points to foo.com/default.aspx:

/0.4/([^/\.]+)$ /0.4/$1.aspx [L]

finally i guess to go down one more level so that foo.com/test/car points to foo.com/test/car.aspx:

/0.4/([^/\.]+)/([^/\.]+)$ /0.4/$1/$2.aspx [L]

what do you think?

Coordinator
Aug 5, 2009 at 6:45 PM

The first rule you have...

  RewriteRule ^/0.4/   /0.4/default.aspx  

...matches any URL that begins with /0.4/. Because you don't have an "end of line" symbol on that pattern, it matches anything and regardless of what comes after '/0.4/', if anything, the URL gets rewritten.

If you want to just rewrite the short URL /0.4/ to default.aspx, then just append the $ to the pattern:

  RewriteRule ^/0.4/$   /0.4/default.aspx  

But I would want to make the slash optional also. Hence:

  RewriteRule ^/0.4/?$   /0.4/default.aspx  

The question mark in the pattern above is a quantifier, saying "zero or one of the previous thing". And the previous thing is the slash. So that pattern matches /0.4 and /0.4/, but not /0.4/hello.

Your other two rules should work just fine.  (Notice that they already have the $ as the terminating symbol in the pattern)

 

Aug 6, 2009 at 12:34 AM

It all works as intended.

Thanks for all your help and well done on creating a really useful filter that's worthy of a donation!

Coordinator
Aug 6, 2009 at 1:29 AM

Thanks for the compliments and good luck with that website.