Score:1

IIS 10 URL Rewrite giving 404 error

co flag
SBO

I am currently stuck with my rewrite rules, and I would need some hints about it.

Here's the situation : We have two websites, one is website.com, the other one is website-staging.com (just examples here ofc)

On website.com, for some url, I'd like to use a rewrite rule to hit the staging website and display the results.

Here's the rule in the web.config file :

<rule name="RewriteSearchQueries" patternSyntax="Wildcard" stopProcessing="true">
<match url="search?*" />
<action type="Rewrite" url="https://website-staging.com/{R:0}" logRewrittenUrl="true" />

I did the pattern test, everything's ok. The URL used for the rewrite is working properly, however when I hit website-staging.com/search?arg=1&blabla=2, I have a 404 error message :

404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

I did try to put the following action as well :

<action type="Rewrite" url="https://website-staging.com/search?{R:1}" logRewrittenUrl="true" />

And it didn't work either. Any clue ?

EDIT : Application Request Routing is installed, the proxy is enabled.

Lex Li avatar
vn flag
With FRT enabled, https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules you should be able to help yourself. Hints: queries are not processed in `match` tag, so your pattern won't work. You should use a condition instead. Use a search engine to find examples on query strings.
SBO avatar
co flag
SBO
Thanks, FRT Indeed helped, will post an answer :)
Score:0
co flag
SBO

So.. After installing FRT as advised by Lex Li, I saw that there was no match, therefore no URL rewriting was done.

I did test again and again the pattern, everything was fine.

Finally, I decided to replace the wildcard by regex, and.. Tadam ! It worked. For a reason that I can't explain, the wildcard pattern wasn't detected properly, despite being OK with the pattern tester, while using regex did the trick perfectly.

So, if you're facing a similar issue, regex all the way !

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.