1

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.

Nikhil
  • 88
  • 4
SBO
  • 524
  • 4
  • 12
  • 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. – Lex Li Jul 06 '21 at 14:56
  • Thanks, FRT Indeed helped, will post an answer :) – SBO Jul 15 '21 at 12:07

1 Answers1

0

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 !

SBO
  • 524
  • 4
  • 12