相对路径不适用于 IIS 重写

发布于 2024-12-09 20:22:11 字数 2290 浏览 0 评论 0 原文

我有一个网站,当人们导航到 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>

I have a site, that when people navigate to http://subdomain.mysite.com/ it is rewritten to

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

and then when people navigate to http://subdomain.mysite.com/AnythingElse.aspx it is then rewritten to http://mysite.com/clientArea/AnythingElse.aspx

The problem comes in with the stylesheets, for some reason they are resolving incorrectly.

In my code I have them entered like such

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

But when I try to visit my website at http://subdomain.mysite.com/ and look at the source, they have changed to this

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

Which doesn't work because it's trying to get a resource from

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

where it should be trying to get the resources from

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

I've tried a bunch of various fixes including adding in a Page.RequestUrl with the ~ and such, but they all add the clientArea in front. Which doesn't work since we're already in the clientArea folder.

Any help with this matter would be great.

Here are my rewrite rules

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挥剑断情 2024-12-16 20:22:12

尝试使用 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();
                }
            }
        }

,并在 Web 配置中编写规则的其余部分并尝试。

Try to use URLRewriter.dll and apply below code in 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();
                }
            }
        }

And write rest of the Rule in web config and try it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文