Return 404.4 Not Found when URL Rewrite

URL Rewrite module can redirect a URL to any internal (on the same site) or external URLs (on a separate site).

https://www.iis.net/download/urlrewrite

However, URLRewrite rewrite rule to external site doesn’t work. You can only rewrite the URL in the same site and same application pool.

For example, let’s set following rule to rewrite original Requested URL: https://localhost/81 to https://localhost:81

<rewrite>

            <globalRules>

                <rule name="URLTest">

                    <match url="([0-9]+)" />

                    <action type="Rewrite" url="https://localhost:{R:1}" appendQueryString="true" />

                </rule>

            </globalRules>

 </rewrite>

Test https://localhost/81 and return HTTP Error 404.4- Not Found

The resource you are looking for does not have a handler associated with it.

Check FREB Log, it shows RewriteModule execute successfully

14.

PRE_BEGIN_REQUEST_START

ModuleName="RewriteModule"

15.

i

URL_REWRITE_START

RequestURL="/81", Scope="Global", Type="Inbound"

16.

RULE_EVALUATION_START

RuleName="URLTest", RequestURL="81", QueryString="", PatternSyntax="Regex", StopProcessing="false", RelativePath="/"

17.

PATTERN_MATCH

Pattern="([0-9]+)", Input="81", Negate="false", Matched="true"

18.

REWRITE_ACTION

Substitution="https://localhost:{R:1}", RewriteURL="https://localhost:81", AppendQueryString="true", LogRewrittenURL="false"

19.

RULE_EVALUATION_END

RuleName="URLTest", RequestURL="https://localhost:81", QueryString="", StopProcessing="false", Succeeded="true"

20.

GENERAL_SET_REQUEST_HEADER

HeaderName="X-Original-URL", HeaderValue="/81", Replace="true"

21.

i

URL_CHANGED

OldUrl="/81", NewUrl="https://localhost:81"

22.

i

URL_REWRITE_END

RequestURL=https://localhost:81

 

But it fails with 404.4 in IIS Web Core.

156.

r

MODULE_SET_RESPONSE_ERROR_STATUSWarning

ModuleName="IIS Web Core", Notification="MAP_REQUEST_HANDLER", HttpStatus="404", HttpReason="Not Found", HttpSubStatus="4", ErrorCode="The filename, directory name, or volume label syntax is incorrect.

 (0x8007007b)", ConfigExceptionInfo=""

 

Solution

======

You need to install Application Request Routing and enable Proxy, then it will work with URL rewriting to remote servers (regardless where or what they are) since the Routing will take care of that.

https://www.iis.net/download/ApplicationRequestRouting

Enjoy!

Anik