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
Related
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,
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>
I have an old url www.mydomain.com/customer/1. I changed that server to ww2 and it displays fine at ww2.mydomain.com/customer/1. On my new IIS 8.5 www server how can I put in a rewrite rule so if the user goes to www.mydomain.com/customer/1 they will redirect to ww2.mydomain.com/customer/1. I have tried numerous patterns in the Url Rewrite 2.0 module and nothing seems to work. All other www requests I do not want redirected, those stay on my new www server.
I you want to redirect a single path, /customer/1, then you should add this to Web.config on the www.mydomain.com server:
<rewrite>
<rules>
<rule name="Redirect 'www.mydomain.com/customer/1' to 'ww2.mydomain.com/customer/1'" stopProcessing="true">
<match url="^customer/1$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.mydomain\.com$" />
</conditions>
<action type="Redirect" url="http://ww2.mydomain.com{REQUEST_URI}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
If you wish to include additional paths, you can fiddle with the RegEx specified in the <match url="^customer/1$" /> tag.
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
I have hosted an Orchard site locally on my machine on IIS 8.0 using SQL LocalDb.
I have also installed and integrated the URL Rewrite module in IIS.
I have modified the web.config in the Orchard.Web project for redirecting as
<rewrite>
<rules>
<rule name="Redirect services to expertise" stopProcessing="true">
<match url="/services/(.*)" />
<action type="Redirect" url="/expertise/{R:1}" />
</rule>
</rules>
</rewrite>
So, what I intend to do is redirect from "http://localhost:70/Orchard/services/content-management" to "http://localhost:70/Orchard/expertise/content-management".
But this is not working as intended and there is no redirection. It opens up the same old "../services/.." URL.
Any Ideas?
Thanks in Advance.
I believe the issue is with your rule. The url does not have a leading slash. Try change the rule to:
<rule name="Redirect services to expertise" stopProcessing="true">
<match url="^services/(.*)" />
<action type="Redirect" url="expertise/{R:1}" />
</rule>
This will redirect any url starting with services/... to expertise/...