繁体   English   中英

相对路径不适用于IIS Rewrite

[英]Relative Paths not working with IIS Rewrite

我有一个网站,当人们浏览到http://subdomain.mysite.com/时,它被重写为

http://mysite.com/clientArea/Default.aspx?ID=1234

然后当人们导航到http://subdomain.mysite.com/AnythingElse.aspx时,它将被重写为http://mysite.com/clientArea/AnythingElse.aspx

该问题来自样式表,由于某种原因,它们无法正确解决。

在我的代码中,我这样输入了它们

<link rel="Stylesheet" href="css/myStyleSheet.css" type="text/css" media="screen" />

但是,当我尝试访问我的网站http://subdomain.mysite.com/并查看源时,他们已更改为

<link rel="Stylesheet" href="clientArea/css/myStyleSheet.css" type="text/css" media="screen" />

这不起作用,因为它正在尝试从中获取资源

http://subdomain.mysite.com/clientArea/css/myStyleSheet.css

应该从哪里获取资源

http://subdomain.mysite.com/css/myStyleSheet.css

我已经尝试了多种修复程序,包括使用〜等添加Page.RequestUrl,但是它们都在前面添加了clientArea。 由于我们已经在clientArea文件夹中,因此无法使用。

在这件事上的任何帮助将是巨大的。

这是我的重写规则

<rule name="Remove Subdomain" enabled="true" stopProcessing="true">
                <match url="^$" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^(?!www)subdomain\.mysite\.com$" />
                </conditions>
                <action type="Rewrite" url="clientArea/?ID=1234" appendQueryString="true" logRewrittenUrl="true" />
            </rule>
            <rule name="Everything Else" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^(?!www)subdomain\.mysite\.com$" />
                </conditions>
                <action type="Rewrite" url="clientArea/{R:0}" />
            </rule>

尝试使用URLRewriter.dll并在Global.ascx中应用以下代码

if (Request.Url.AbsoluteUri.EndsWith(".jpg") || Request.Url.AbsoluteUri.EndsWith(".gif") ||
           Request.Url.AbsoluteUri.EndsWith(".png") || Request.Url.AbsoluteUri.EndsWith(".ico") ||
           Request.Url.AbsoluteUri.EndsWith(".js") || Request.Url.AbsoluteUri.EndsWith(".css"))
        { }
        else
        {
            if (!Convert.ToString(arrPath[1]).Equals("admin", StringComparison.CurrentCultureIgnoreCase))
            {
                if (!Convert.ToString(arrPath[1]).Equals("demo.aspx", StringComparison.CurrentCultureIgnoreCase))
                {
                    URLRewriter.Rewriter.Process();
                }
            }
        }

并在网络配置中编写其余规则,然后尝试。

暂无
暂无

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

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