newbie:stop rewriting of internal links

Topics: Developer Forum
Jan 19, 2008 at 9:40 AM
I am starting to use IIRF and trying to acheive something as basic as -
http://localhost/CO1001 = http://localhost/showComp.asp?clientid=CO1001

I am using -

RewriteLog c:\temp\iirf
RewriteLogLevel 2
#RewriteRule ^/(.+)$ /showComp.asp?clientid=$1 L
RewriteRule ^/comp/(.+)$ /showComp.asp?clientid=$1 L

This is working but the the page is not showing properly on study of the log I found all the css and image links in the page have been re-written like -

Sat Jan 19 14:55:43 2008 - New Url: '/comp/styletx.css'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 34): /showComp.asp?clientid=styletx.css

How to prevent this?

Also I would like to have -
http://localhost/CO1001 = http://localhost/showComp.asp?clientid=CO1001 but if I use the RULE as -
RewriteRule ^/(.+)$ /showComp.asp?clientid=$1 L

This is rewriting even the basic http://localhost/ !

Arijit

This is complete Log:
---------------------------------------
--------------------------------------------
Sat Jan 19 14:55:42 2008 - Read .ini file: setting LogLevel to 2
Sat Jan 19 14:55:42 2008 - ini line 5: RewriteRule 1 ^/comp/(.+)$ /showComp.asp?clientid=$1 L
Sat Jan 19 14:55:42 2008 - ParseRuleModifierFlags: 'L'
Sat Jan 19 14:55:42 2008 - Done reading .ini file: Found 1 rules (0 failed) on 6 lines
Sat Jan 19 14:55:42 2008 - Ionic URL Rewriting ISAPI Filter v1.2.12c
Sat Jan 19 14:55:42 2008 - Initialize, main threadId= 3160
Sat Jan 19 14:55:42 2008 - File watcher thread created.
Sat Jan 19 14:55:42 2008 - GetFilterVersion
Sat Jan 19 14:55:42 2008 - New Url: '/comp/CO0948'
Sat Jan 19 14:55:42 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:42 2008 - Result (length 29): /showComp.asp?clientid=CO0948
Sat Jan 19 14:55:42 2008 - Last if Match
Sat Jan 19 14:55:42 2008 - Rewrite Url to: '/showComp.asp?clientid=CO0948'
Sat Jan 19 14:55:42 2008 - DllMain THREAD_DETACH, threadId= 3156
Sat Jan 19 14:55:43 2008 - DllMain THREAD_DETACH, threadId= 2968
Sat Jan 19 14:55:43 2008 - New Url: '/comp/styletx.css'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 34): /showComp.asp?clientid=styletx.css
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=styletx.css'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/stylebg.css'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 34): /showComp.asp?clientid=stylebg.css
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=stylebg.css'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/includes/common.js'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 41): /showComp.asp?clientid=includes/common.js
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=includes/common.js'
Sat Jan 19 14:55:43 2008 - New Url: '/images/index_01.gif'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/images/index_02.jpg'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/images/index_04.jpg'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/ex_02.gif'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 39): /showComp.asp?clientid=images/ex_02.gif
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/ex_02.gif'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/find-button.jpg'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 45): /showComp.asp?clientid=images/find-button.jpg
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/find-button.jpg'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/spacer.gif'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 40): /showComp.asp?clientid=images/spacer.gif
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/spacer.gif'
Sat Jan 19 14:55:43 2008 - New Url: '/images/book.gif'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/images/feedback.gif'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/images/print.gif'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/ex_01.gif'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 39): /showComp.asp?clientid=images/ex_01.gif
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/ex_01.gif'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/ex_03.gif'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 39): /showComp.asp?clientid=images/ex_03.gif
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/ex_03.gif'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/ex_04.gif'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 39): /showComp.asp?clientid=images/ex_04.gif
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/ex_04.gif'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/Medium/3162-1011.jpg'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 43): /showComp.asp?clientid=Medium/3162-1011.jpg
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=Medium/3162-1011.jpg'
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/ex_08.gif'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 39): /showComp.asp?clientid=images/ex_08.gif
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/ex_08.gif'
Sat Jan 19 14:55:43 2008 - New Url: '/images/index_05.jpg'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/comp/images/ex_11.gif'
Sat Jan 19 14:55:43 2008 - Rule 1 : 2 matches
Sat Jan 19 14:55:43 2008 - Result (length 39): /showComp.asp?clientid=images/ex_11.gif
Sat Jan 19 14:55:43 2008 - Last if Match
Sat Jan 19 14:55:43 2008 - Rewrite Url to: '/showComp.asp?clientid=images/ex_11.gif'
Sat Jan 19 14:55:43 2008 - New Url: '/images/index_25.jpg'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:55:43 2008 - New Url: '/images/index_28.jpg'
Sat Jan 19 14:55:43 2008 - No Rewrite
Sat Jan 19 14:56:52 2008 - DllMain THREAD_DETACH, threadId= 3236
Sat Jan 19 14:56:52 2008 - DllMain THREAD_DETACH, threadId= 3240
Sat Jan 19 14:56:52 2008 - DllMain THREAD_DETACH, threadId= 3244
Sat Jan 19 14:57:53 2008 - DllMain THREAD_DETACH, threadId= 3248
Sat Jan 19 14:57:53 2008 - DllMain THREAD_DETACH, threadId= 3256
Sat Jan 19 14:58:08 2008 - Detected change in the ini file. . .
Sat Jan 19 14:58:08 2008 - Ionic URL Rewriting ISAPI Filter v1.2.12c
Sat Jan 19 14:58:08 2008 - ReadConfig
Sat Jan 19 14:58:08 2008 - LogFile re-opened.
Sat Jan 19 14:58:08 2008 - Read .ini file: new log file name: c:\temp\iirf.3108.log
Sat Jan 19 14:58:08 2008 - Read .ini file: setting LogLevel to 2
Sat Jan 19 14:58:08 2008 - ini line 4: RewriteRule 1 ^/comp/(.+)$ /showComp.asp?clientid=$1 L
Sat Jan 19 14:58:08 2008 - ParseRuleModifierFlags: 'L'
Sat Jan 19 14:58:08 2008 - Done reading .ini file: Found 1 rules (0 failed) on 5 lines
Coordinator
Jan 30, 2008 at 6:19 PM
If you want to prevent stylesheets and images from satisfying the rule (and then being rewritten) then, use a regex that excludes those URLs. Your original is like this:
RewriteLog c:\temp\iirf
RewriteLogLevel 2
#RewriteRule ^/(.+)$ /showComp.asp?clientid=$1 L
RewriteRule ^/comp/(.+)$ /showComp.asp?clientid=$1 L

This satisfies any URL. If you want to exclude all css files, then use a negative lookahead, something like this:
RewriteRule (?!.*\.css)^/comp/(.+)$ /showComp.asp?clientid=$1 L

What this says is, for any URL that does not have a .css within it, and which looks like /comp/something, then rewrite.

You may have to play with it, because the negative lookahead will match any URL with .css in it, including these:
style.css
comp/style.css
this.is.not.a.css.sheet/Hello.htm

The first two, perhaps you want to satisfy the rule. The last one, you may NOT want it to match the rule. In that case you will want to put an end-of-line in the negative lookahead, something like this:
RewriteRule (?!.*\.css$)^/comp/(.+)$ /showComp.asp?clientid=$1 L

as always, test early and often!

good luck!