views:

308

answers:

3
+1  Q: 

URL rewriting

I am using regx for URL rewriting. created a XML file and write the below code in Global.ASAX file

string sPath = Context.Request.Path;

    Context.Items["VirtualURL"] = sPath;
    Regex oReg;
    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
    xmlDoc.Load(Server.MapPath("~/Rule.xml"));
    System.Xml.XmlElement _oRules = xmlDoc.DocumentElement;

    foreach (System.Xml.XmlNode oNode in _oRules.SelectNodes("rule"))
    {
        oReg = new Regex(oNode.SelectSingleNode("url/text()").Value);

        Match oMatch = oReg.Match(sPath);

        if (oMatch.Success)
        {
            sPath = oReg.Replace(sPath,
              oNode.SelectSingleNode("rewrite/text()").Value);
            break;
        }
    }
    Context.RewritePath(sPath);

virtual URL is /ProductDatabaseCMS/Category/Product/A320.aspx

original URL is /ProductDatabaseCMS/Product.aspx?PROD_ID=A320

product.aspx uses master page that has path /ProductDatabaseCMS/Main.master and it include style sheet via path /ProductDatabaseCMS/App_Themes/Styles/Styles.css

when i tried to open product.aspx page via other web page using hyperlink control then style sheet is not working in product.aspx page becuase it takes path

/ProductDatabaseCMS/Category/Product/App_Themes/Styles/Styles.css and all the links in master page also takes the same path

/ProductDatabaseCMS/Category/Product/...

i do not want to include /Category/Product/.. because these two folder path are virtual.

what is the solution for this.


dupe: http://stackoverflow.com/questions/556240/url-rewriting

(answer: use a root relative path)

A: 

It would help to see your config/rules for the rewriter please.

I suspect though that you just need to stop processing any URLs ending in .css at the top of your rewrite rules.

Without knowing which rewriter you are using I can't give any examples.

Iain M Norman
A: 

I agree with teknohippy, do images also not work or just stylesheets? I assume stylesheets aren't running at server?

You could either make stylesheets load using a rel tag that runs at the server with a ~/ url or just make your rewrite rules only applicable to specific file types.

The rewrite rule change is probably best but you may find rel tag is quicker?

Hope this helps

MJJames
As long as the <head> element has a 'runat="server"', the style sheet <link> only requires a tilde to represent the application path
Nick
A: 

~/yourpathtoyourcss.css

tilda slash it up

hunter