简体   繁体   中英

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: URL Rewriting

(answer: use a root relative path)

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.

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?

~/yourpathtoyourcss.css

tilda slash it up

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM