IIS URL Redirect with input parameters - redirect

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>

Related

IIS 10 URL redirect from one domain to another

I would like to redirect a specific site from one domain to another and i have tried the following URL redirect. Not sure where i am going wrong.
I have an app at http://www.a.b.com/myapp/index.aspx
I would like to redirect it to
http://www.a.c.com/myapp/index.aspx
<rule name="testredirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^myapp/index.aspx$" />
<action type="Redirect" url="http://www.a.c.com/{R:0}" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.a.b.com$" />
</conditions>
</rule>
The rule work perfectly on my side. Please try to clean browser cache and post your detailed error message. Please ensure you are running the rule in the right place and has been enabled.
Besides, please check whether the incoming request is reaching the correct application pool.

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>

How to Redirect a Domain without Changing the URL in web.config file?

I setup a redirect from one domain (https://test.mydomain.com) to another URL (http://testing.com/test/Login.aspx) and I want to keep the domain name in the address bar. Basically, Redirect website visitors to another site, but do not show them the destination address, so they do not know about the redirection.
This is for a windows server 2008 r2, running iis 7. I would like to amend the web.config file.
I expect the redirect to keep the original domain (https://test.mydomain.com).
According to your description, I suggest that you use URL Rewrite.
First add the condition to check whether URL is a https request, then add another condition to check the domain of URL. Add the rule below to your web.config file.
<rule name="test url rewrite">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
<add input="{HTTP_HOST}" pattern="test.mydomain.com" />
</conditions>
<action type="Rewrite" url="http://testing.com/test/Login.aspx" />
</rule>

IIS Redirects to multiple domains and preserves the request file path and names

I'm running IIS 8, Windows Server 2012.
My website has many sub-directories. An ideal url will look like:
oldsite.com/subdir/subdir/pages/default.aspx
I need to redirect (301) visitors to different domains and need to preserve the rest of the original url's file path (everything from the 2nd to the last slash "/").
I have a map of my redirects in an excel sheet, it looks like below:
oldsite.com/subdirA/subdirB/pages/default.aspx -> newsiteA.com/subdirC/subdirD/pages/default.aspx
So you see the whole thing has to change except the last part.
My web.config looks like this:
<rewrite>
<rewriteMaps>
<rewriteMap name="RedirectsCollectionParshareSites">
<add key="/subdirA/subdirB/" value="/subdirC/subdirD/" />
<!--will have many of these add keys-->
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Rule1 for RedirectsCollectionParshareSites">
<match url="^(.+)" />
<conditions>
<add input="{RedirectsCollectionParshareSites:{REQUEST_URI}}" pattern="^([^/]+)/([^/]+)(.*)" />
</conditions>
<action type="Redirect" url="http://newsiteA.com/{C:1}{C:3}" appendQueryString="true" />
</rule>
</rules>
My wish is to have many "add keys" - with the mapping from my excel sheet, and per new domain, I will have a new "rewriteMaps" section, with it's own "action".
My question is, is this the proper way of using this module? Any other suggestions?
Remember, I have about a thousand of these redirects to implement.
Any help would be appreciated.
I wasn't able to use the rewritemaps approach, but was able to do it by doing a rule per site:
<rule name="Rule:tes" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="^(\/subdirA)(\/subdirB)(.*)" />
</conditions>
<action type="Redirect" url="http://newsite.com/subdirC/subdirD/{C:3}" />
</rule>
It's harder for admins to update, but it works.

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