web.config rewrite rule not working after adding similar match URL expression - web-config

i am trying to implement following URL rewrite rule in my web.config. The rule i have mentioned below is working fine, the problem is when i add one more valid expression let say |news/Announces-Magento-Partnership to it, site stops working and it give 500 internal server error, i tried making another rule but it is still not working.
<match url="^es/(news/Announces-Autodesk-Forge-Partnership|news/completes-sas-70-certification|news/becomes-oracle-gold-level-partner|news/continues-global-expansion|news/breaks-ground-on-new-headquarters|news/onboards-nine-new-team-members|news/best-places-to-work-2018-honoree|news/101-best-and-brightest-2017|news/2018-healthiest-employers|news/techgateway-day-2017-broward-county|news/best-custom-business-software-developer-2017|news/2018-best-bespoke-software-development-firm|news/reviewed-fastest-growing-tech-2017|news/raises-funds-for-victims-of-harvey|news/makes-incs-honor-roll-sixth-time|news/to-exhibit-at-the-2017-nsc-congress-and-expo|news/joins-ellie-mae-pro-consulting-partner-program|news/announces-expansion-increases-us-team-by-5-new-members|news/announce-a-new-director-of-sales-supply-chain-marketing|news/named-to-south-florida-business-journal-2017-top-private-company-list|news/announce-a-new-director-of-sales-enablement|news/to-exhibit-at-nacds-2017-in-san-diego-ca|news/to-exhibit-at-iltacon-2017-in-las-vegas-nv|news/to-exhibit-at-inman-connect-2017-in-san-francisco-ca|news/to-exhibit-at-infoag-2017-in-st-louis-mo|news/to-exhibit-at-avma-2017-in-indianapolis-in|news/to-exhibit-at-mwaa-2017-in-chicago-il|news/to-exhibit-at-wtc-2017-in-las-vegas-nv|news/to-exhibit-at-invest-2017-in-new-york-city-ny|news/to-exhibit-at-igss-2017-in-amsterdam-netherlands|news/to-exhibit-at-hitec-2017-in-toronto-canada|news/to-exhibit-at-infocomm-2017-in-orlando-fl|news/to-exhibit-at-unite-europe-2017-in-amsterdam-netherlands|news/to-exhibit-at-sabre-travel-technology-exchange-2017-in-las-vega-nv|news/to-exhibit-at-ncsc-2017-in-washington-dc|news/to-recieve-healthiest-employer-award|news/to-exhibit-at-naa-2017-in-atlanta-ga|news/to-exhibit-at-ala-2017-in-chicago-il|news/to-exhibit-at-iste-2017-in-san-antonio-tx|news/to-exhibit-at-hci-2017-in-boston-ma|news/to-exhibit-at-money2020-in-copenhagen-denmark|news/to-exhibit-at-irce-2017-in-chicago-il|news/to-exhibit-at-safety-2017-in-denver-co|news/to-exhibit-at-e3-2017-in-los-angeles-ca|news/to-exhibit-at-cfma-conference-in-phoenix-az)(.*)" />
<action type="Rewrite" url="/{R:1}{R:2}" appendQueryString="true" />
</rule>

Related

IIS redirection rules using query string parameters

I want to make a not-so-common redirection on IIS and I'm not too sure this is possible.
In my case I want to do something like that:
http://www.mywebsite/app/stuff?id=123 to http://www.mywebsite/app2/stuff?id2=456
Since there is nothing in common between the 2 parameters (only a file mapping the old URL and the new one) I was planning to create manual redirection rules for each entries to be redirected.
However my first simple tests showed by that it doesn't seem to work.
Is what I'm trying to achieve even possible? If it is, what am I doing wrong?
Thanks in advance.
According to your description, if you want to modify the querystring by using url rewrite, I suggest you could try to use below rule:
<rule name="MatchQueryString" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=123" />
</conditions>
<action type="Redirect" url="/app2/stuff?id2=456" appendQueryString="false" />
</rule>

IIS URL Redirect with input parameters

Having trouble implementing my first IIS redirect.
I have a URL:
domain.com/Q7WebServer/Q7WebSrv.exe/datasnap/rest
It can accept a range of input parameters separated by / characters:
domain.com/Q7WebServer/Q7WebSrv.exe/datasnap/rest/GetDateTime
domain.com/Q7WebServer/Q7WebSrv.exe/datasnap/rest/GetUsageData
etc, etc.
I'd like to redirect to a new module (a DLL in fact):
domain.com/Q7WebServer/Q7WebSrvISAPI.dll/datasnap/rest
I started by adding my redirect to the file itself (Q7WebSrv.exe) and it works fine by itself. It's only when I add variables that it starts behaving in ways I don't understand. For example if I have the redirect set to Q7WebSrvISAPI.dll$V$Q (using the EXACT flag) and request
domain.com/Q7WebServer/Q7WebSrv.exe
I get back
domain.com/Q7WebServer/Q7WebSrvISAPI.dll/Q7WebServer/Q7WebSrv.exe
No matter which $ variables I use, it's still trying to append part of the original URL to the redirect. I don't even want to get into what happens when appending the / input parameters.
Do I need to get into URL rewriting? That's a whole can of worms I'm not wanting to open just yet.
you could try this rule:
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.domian.com" />
<add input="{REQUEST_URI}" pattern="/Q7WebServer/Q7WebSrv.exe/datasnap/rest/(.*)" />
</conditions>
<action type="Redirect" url="http://ww.domain.com/Q7WebServer/Q7WebSrvISAPI.dll/datasnap/rest/{C:1}" />
</rule>

Creating a IIS Url Rewrite/Redirect

Im struggling to get a url rewrite/redirect to work in IIS. I've installed the url rewrite module and all the rules fail to do anything. Here is the scenario, we want all web requests which generate a report to be pushed off to a secondary server so it doesn't harm the main box. The web requests that generate reports look something like this:
http://mywebaddress/api/Actionname=GenerateReport&param=123
So im wanting to do some type of regex check on finding any web requests that have "GenerateReport" in it and redirect it to something like:
http://mywebaddressofsecondserver/api/Actionname=GenerateReport&param=123
Any ideas on how the redirect/rewrite would go for this?
You need to check if REQUEST_URI contains Actionname=GenerateReport.
If so, you'll redirect it to other webserver url equivalent.
Translated to an IIS rewrite rule, it would look like this
<rule name="Delegate report generation" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_URI}" pattern="Actionname=GenerateReport" />
</conditions>
<action type="Redirect" url="http://mywebaddressofsecondserver/{R:1}" />
</rule>
Thanks, Justin Iurman,
Your answer solved my issue of getting methods
http://mywebaddress/api/Param/Action1
http://localserverwithport/api/Param/Action1
but for below Post methods it's still giving 404 not found
http://mywebaddress/api/Param/PostAction2
http://localserverwithport/api/Param/PostAction2
Post parameters are:
{"Param1":"James","Param2":"jani"}
My implementation is
'<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule1" >
<match url="^(.*)" />
<action type="Redirect" url="http://localserverwithport/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>'

Redirect rule in web.config

I was looking into this Seemingly simple redirect in IIS using web.config file because I have a similar situation, but the approach mentioned there doesn't seem to be working for me.
I have a help section on a web site, which for now I want it to redirect to another place. The rest of the site should stay the same, which means that only the help section/content should make the user go to another site:
device.domain.com/help
device.domain.com/help/version
Should make the request go to
company.custhelp.com
But for example device.domain.com/api should still work. This is what I tried. If I test the pattern inside of IIS it says that it will work. What am I missing?
<system.webServer>
<rewrite>
<rules>
<rule name="Help Redirect" stopProcessing="true">
<match url="(.*)/help(.*)" ignoreCase="true" />
<action type="Redirect" url="http://company.custhelp.com/" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
...
</system.webServer>
The match url will try to match on the path after the domain, starting from after the slash. So it should be like so:
<match url="help(.*)" ignoreCase="true" />
The match url that you wrote would match on device.domain.com/temp/help, but not device.domain.com/help.

Rewrite Maps in IIS7 - Not redirecting

I'm trying to use a separate config file, named "rewritemaps.config", that contains the URLs I want to redirect. The file is in the root directory (same place as the web.config). The format of the Redirects.config file I have is:
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="aspx/drvmain.aspx"
value="http://www.newdomain.com/folder2/page2.aspx" />
<add key="aspx/jobs_AboutUs.aspx"
value="http://www.newdomain.com/folder1/jobs.aspx" />
<add key="aspx/page.aspx"
value="http://www.newdomain.com/folder1/page2.aspx" />
</rewriteMap>
</rewriteMaps>
In my web.config file, I have:
<system.webServer>
<rewrite>
<rewriteMaps configSource="rewritemaps.config" />
<rules>
<rule name="Redirect rules">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" redirectType="Permanent"
url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewriteMaps>
</rewrite>
</system.webServer>
In the IIS Manager (which, yes, I have installed the URL Rewrite module), I've even gone and tested the rule and condition against one of my URLs in the redirects.config file and it says it works. But then when I try going to the URL in my browser, it doesn't redirect as I've specified. In the rewritemaps.config file, I've tried putting the full domain, and I've tried with a "/" before aspx. Nothing seems to work. I'm not sure what I'm missing here.
Well I got it working. Was something stupid. In the rewritemaps.config file, I needed "/"s before the key URL. I know I had tried that before, but I must have been missing something somewhere else at the time. Oh well. It works now.
It is really hard to determine why this is failing but the best thing you can do is use Failed Request Tracing so that IIS tells you what is happening. With FREB you will get detailed tracing telling you which rules were evaluated and if they matched or they didn't and why not. You can also see the "right" patterns to match and every condition that is evaluated.
See the following link:
http://www.iis.net/learn/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules