views:

258

answers:

2

I've written URL using Helicon ISAPI Rewrite v3 for following:

www.foo.com/tags/tag1 --> www.foo.com/Pages/Articles/ArticleListing.aspx?tags=tag1

But the .css, .js i've refered are being accessed by browser as

www.foo.com/tags/tag1/style.css
www.foo.com/tags/tag1/myjs.js

but these files are located as

www.foo.com/css/style.css
www.foo.com/js/myjs.js

Without hardcoding the domain name "www.foo.com", how i can achieve wrong referencing?

A: 

One trick for handling CSS and other static files i.e. images and javascript, is to include a base tag in the head section of your page e.g.

That way, all your CSS paths, etc. will be resolved relative to the href in the base tag.

For more info you can check this post: http://chriscavanagh.wordpress.com/2008/11/06/aspnet-routing-just-enough-rope/

Shoaib Shaikh
A: 

First, verify that your RewriteRule is not including more than just tags. A simple fix might be to put this RewriteCond on the line before your RewriteRule.

RewriteCond %{REQUEST_FILENAME} !(.js|.css|.gif|.jpg)

Your stylesheet link tag can be simply:

  <link href="/css/style.css" rel="stylesheet" type="text/css" />
James Lawruk
Do i need to add this RewriteCond before every RewriteRule in my .htaccess file? or adding once will do?
ParagM
Unfortunately, the RewriteCond only applies to the rule on the next line. I honestly don't know if there is a way to apply it to all rules.
James Lawruk