How to rewrite a domain to another one in IIS 10? - iis

I have the following website configuration on IIS 10.
<rewrite>
<rules>
<rule name="Rule1">
<match url=".*" />
<action type="Rewrite" url="https://www.google.com/{R:0}" />
</rule>
</rules>
</rewrite>
I'm trying to rewrite all the requests sent to mydomain.com to google.com (taken as an example)
When running the website, I'm getting the following google error page in the screenshot. Means the rewrite is not behaving properly and doesn't send requests to the domain www.google.com
Can anyone help please ?
Thanks. Regards,

Related

Issue with redirection in IIS?

I have the following rule in IIS
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" patternSyntax="ExactMatch" stopProcessing="true">
<match url="apex" />
<action type="Redirect" url="http://{HTTP_HOST}:8080/ords/f?p=1" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
This rule works fine and redirects URL's from
www.example.com/apex
to
www.example.com:8080/ords/f?p=1
I would like to get an URL without the port 8080 in it. So, when I change the rule type to Rewrite. It doesn't work any more. It ommits the port and I'm getting the error : 404 - File or directory not found
Does anyone know how to solve that please ?
Thanks.
Regards,
I guess you are getting 404.4. If you didn't enabled detailed error message for your website. Then you will get 404 File or directory not found.
Please install failed request tracing
https://www.microsoft.com/en-us/download/details.aspx?id=47333.
Then go to IIS manager->server node->application request routing cache->server proxy setting->enable proxy.

Rewrite rule not working on IIS with using Regex

I'm trying to write a rewrite rule in on Windows Server 6.2. Although I used IIS Manager to create the code, it didn't work.
I tried stopProcess true/false, used different regex, restart server several times. Nothing changed. I followed the whole steps on Microsoft's web site on https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="[^\/]+\/\/([^\/]+:?[0-9]?)\/.*" />
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I want to show only main URL. My domain is http://e-campus.example.com.
For example if someone go to that link: http://e-campus.example.com/Login/Student
Server should rewrite to this:
e-campus.example.com (with hiding http:// but it's not important)
So basically I just want to show main URL. But it keeps showing full path. What am I missing here?
According to your description, I found your regex match the whole url. But the iis url rewrite will not get the whole domain, it will just get the part of the url not the whole url.
For example:
If your url is http://e-campus.example.com/Login/Student., the match url part is
login/Student.
So if you want to rewrithe all the request to e-campus.example.com, you should use below url rewrite rule.
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://e-campus.example.com/" />
</rule>
</rules>
</rewrite>
</system.webServer>

IIS URL Redirect failing

I need to redirect URLs of the form:
http://server1.name.here/path1/path2/?num=123456
to:
http://server2.name.here/path3/path2/?num=123456
using the IIS URL Rewrite Module 2.0 on IIS 8.5. I've used a DNS alias to handle the server name redirection.
I've been using the user interface to configure the path rewrite but despite trying several variations and extensive research I cannot get my rewrite to work, which is slightly embarrassing as I feel this should be a simple rewrite. The web.config produced by the URL rewite user interface is:
<rewrite>
<rules>
<rule name="path rewrite" patternSyntax="ECMAScript" stopProcessing="false">
<match url="path1/path2/" ignoreCase="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="num=[0-9]+" />
</conditions>
<action type="Rewrite" url="path3/path2/" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
When I try to open server1.name.here/path1/path2/?num=123456 I get a "403 - Forbidden: Access is denied." and the logs show no evidence that my URL is being rewritten or even flagged by the rewrite rule.
I'm sure I'm missing something obvious, can anyone enlighten me as to what I've got wrong?
Many Thanks Eden

Redirect “/” to “/web” using IIS7

I'm hosting a site where I would like for various reasons to have http://mydomain.com automatically redirect to http://mydomain.com/web while at the same time still allowing http://mydomain.com/foo.html to be served.
Using HTTP Redirect from IIS 7 I seem to be creating an endless redirect loop. Would you have any hints for me?
Give URL Rewrite Module a try. Following code should work for you :
<rewrite>
<rules>
<rule name="Redirect example.com to example.comn/web" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/web" />
</rule>
</rules>
</rewrite>
How you can get start with Rewrite Module is briefly documented on below post :
http://www.tugberkugurlu.com/archive/remove-trailing-slash-from-the-urls-of-your-asp-net-web-site-with-iis-7-url-rewrite-module

IIS7 rewrite for REST not working

I have a REST service and am trying to remove the .svc - a common task/problem.
The application on the server is in a virtual directory under the default website (not sure if this is important)
I have installed the IIS Rewrite Module and have tried to create a rewrite rule for this.
http://blah.me.com/here/thingys/get?id=1111
to rewrite to this:
http://blah.me.com/service.svc/thingys/get?id=1111
In my web.conf the following is created:
<rewrite>
<rules>
<rule name="GEAPI /here/ to /service.svc/">
<match url="^(.*?)/here/(.*)$" />
<action type="Rewrite" url="{R:1}/service.svc/{R:2}" />
</rule>
</rules>
</rewrite>
In the GUI the regular expression does test correctly.
However - when I run this in a browser on the server, it gives the following 404 error:
Error Code 0x80070002
Requested URL http://blah.me.com:80/here/thingys/get?id=1111
Physical Path C:\MyApp\here\thingys\get
C:\Myapp is the correct physical directory the virtual directory in IIS is pointing to.
Is there something I am missing here ? I have tried creating this rule under both the default website and the app, both separately and together.
Big thanks
P
You could use this:
<rewrite>
<rules>
<rule name="GEAPI /here/ to /service.svc/">
<match url="^(.*)here(/.+)" />
<action type="Rewrite" url="{R:1}service.svc{R:2}" />
</rule>
</rules>
</rewrite>
IIS will only give you the part of the URI that's after http://blah.me.com/

Resources