简体   繁体   English

URL重写

[英]URL rewriting

I am using regx for URL rewriting. 我正在使用regx进行URL重写。 created a XML file and write the below code in Global.ASAX file 创建了一个XML文件,并将以下代码写入Global.ASAX文件

string sPath = Context.Request.Path; 字符串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 虚拟URL是/ProductDatabaseCMS/Category/Product/A320.aspx

original URL is /ProductDatabaseCMS/Product.aspx?PROD_ID=A320 原始URL是/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 product.aspx使用的母版页具有/ProductDatabaseCMS/Main.master路径,并且通过/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 当我尝试使用超链接控件通过其他网页打开product.aspx页面时,样式表在product.aspx页面中不起作用,因为它需要路径

/ProductDatabaseCMS/Category/Product/App_Themes/Styles/Styles.css and all the links in master page also takes the same path /ProductDatabaseCMS/Category/Product/App_Themes/Styles/Styles.css和母版页中的所有链接也采用相同的路径

/ProductDatabaseCMS/Category/Product/... / ProductDatabaseCMS /类别/产品/ ...

i do not want to include /Category/Product/.. because these two folder path are virtual. 我不想包含/ Category / Product / ..,因为这两个文件夹路径是虚拟的。

what is the solution for this. 解决方案是什么?


dupe: URL Rewriting dupe: URL重写

(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. 我怀疑尽管您只需要停止处理重写规则顶部以.css结尾的所有URL。

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? 我同意teknohippy的观点,图像是否还不能正常工作? 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. 您可以使用在服务器上运行的带有〜/ url的rel标记来加载样式表,或者仅使重写规则仅适用于特定文件类型。

The rewrite rule change is probably best but you may find rel tag is quicker? 重写规则更改可能是最好的,但是您可能会发现rel标签更快?

~/yourpathtoyourcss.css 〜/ yourpathtoyourcss.css

tilda slash it up 蒂尔达削减

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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