最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - Wrong physical path when using URL Rewrite in IIS - Stack Overflow

programmeradmin3浏览0评论

I have a simple ASP website running on IIS on port 81 on a Windows 11 PC with the latest ASP.NET Core Runtime 8.0.14 hosting bundle installed and the website is compiled for .NET 8.

Accessing the website through localhost:81 works just fine.

I have installed URL Rewrite and Application Request Routing (and enabled the proxy) and setup a simple rule to map any incoming requests to localhost/mysite to localhost:81:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="ReverseProxyInboundRule" stopProcessing="true">
          <match url="^mysite/(.*)$" />
          <action type="Rewrite" url="http://localhost:81/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

When accessing the website through localhost/mysite I get a 404:

I have used this URL Rewrite rule before and it normally works but the error message says that the Physical Path is C:\inetpub\wwwroot\mysite\ but the real physical path is C:\Websites\mysite.

I have tried setting up Failed Request Tracing but I don't get any output in C:\inetpub\logs\FailedReqLogFiles:

<tracing>
    <traceFailedRequests>
        <add path="*">
            <traceAreas>
                <add provider="ASP" verbosity="Verbose" />
                <add provider="ISAPI Extension" verbosity="Verbose" />
                <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket" verbosity="Verbose" />
            </traceAreas>
            <failureDefinitions statusCodes="100-999" />
        </add>
    </traceFailedRequests>
</tracing>

If I should be so lucky that someone with deeper knowledge of why this happens should read this post I will definitely welcome some guiding!

I have a simple ASP website running on IIS on port 81 on a Windows 11 PC with the latest ASP.NET Core Runtime 8.0.14 hosting bundle installed and the website is compiled for .NET 8.

Accessing the website through localhost:81 works just fine.

I have installed URL Rewrite and Application Request Routing (and enabled the proxy) and setup a simple rule to map any incoming requests to localhost/mysite to localhost:81:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="ReverseProxyInboundRule" stopProcessing="true">
          <match url="^mysite/(.*)$" />
          <action type="Rewrite" url="http://localhost:81/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

When accessing the website through localhost/mysite I get a 404:

I have used this URL Rewrite rule before and it normally works but the error message says that the Physical Path is C:\inetpub\wwwroot\mysite\ but the real physical path is C:\Websites\mysite.

I have tried setting up Failed Request Tracing but I don't get any output in C:\inetpub\logs\FailedReqLogFiles:

<tracing>
    <traceFailedRequests>
        <add path="*">
            <traceAreas>
                <add provider="ASP" verbosity="Verbose" />
                <add provider="ISAPI Extension" verbosity="Verbose" />
                <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket" verbosity="Verbose" />
            </traceAreas>
            <failureDefinitions statusCodes="100-999" />
        </add>
    </traceFailedRequests>
</tracing>

If I should be so lucky that someone with deeper knowledge of why this happens should read this post I will definitely welcome some guiding!

Share Improve this question asked Mar 31 at 14:03 ChauChau 5,5709 gold badges67 silver badges99 bronze badges 2
  • docs.lextudio/jexusmanager/tutorials/… everything starts from valid sites and bindings. So, when your rewriting rules (or other settings) are on a port 81 site, they are not part of the port 80 site and won’t work there. BTW, this isn’t some deep knowledge as IIS books put it in the first few chapters. – Lex Li Commented Mar 31 at 15:58
  • So what you are not saying is that I am doing this completely wrong by having a site on port 81 and using URL Rewrite to redirect to it? – Chau Commented Apr 1 at 6:23
Add a comment  | 

1 Answer 1

Reset to default 1

Try to set the url rewrite rule pattern as shown below:

^mysite/?(.*)

OR

^mysite(.*)

and make sure you have added the rule to the iis default website

发布评论

评论列表(0)

  1. 暂无评论