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>
Related
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.
Is it possible to remove a directory from a URL without using a redirect action? In other words can I do it with only a "rewrite" action.
I need to take a URL like this: http://www.example.com/de/folderabc/specs/default.aspx and remove the "folderabc" directory to make it like this: http://www.example.com/de/specs/default.aspx
So far any variation I have tried like this is not working:
<system.webServer>
<rewrite>
<rules>
<rule name="removefolder" stopProcessing="true">
<match url="folderabc/(.*)" />
<action type="Rewrite" url="/{R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
I am using IIS 7.5.
Try putting a caret ^ in your url to match on.
<match url="^folderabc/(.*)" />
I'm trying to set the canonical URL for my site (macton.com) to add the www in the beginning. The site is hosted using IIS and I installed the URL Rewriter Extension.
Here is the code I put in the web.config file. However, it doesn't seem to do anything, because it remains macton.com.
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^macton\.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.macton.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
After this I have a bunch of <location> tags with redirects that work fine. I tried using a redirect from macton.com → www.macton.com but that just creates an infinite redirect loop (DUH!)
Any idea why this wouldn't be working? Everywhere I look says this is the correct code!
This link can help:
http://www.awseibert.net/how-to/redirecting-canonical-names-in-iis-7
Have you also added macton.com to the binding of your website?
I have two domains: first.com and second.com.
In these domains there are two ASP.NET applications hosted in IIS 7.
Page in application http://first.com.index references a script which source is http://second.com/script.js
Script is doing some ajax POST but browser is blocking is because cross domain restriction.
Is it possible to create rule on IIS so a specific request for http://first.com/script.js
would be passed to http://second.com/script.js (executed there and returned to client) ?
I tried to add rewrite rule in first.com but it does not work:
<system.webServer>
<rewrite>
<rules>
<rule name="test" enabled="true" stopProcessing="false">
<match url=".*/script.js" />
<action type="Rewrite" url="http://second/script.js" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
Action type="Redirect" works but it is not what I am looking for cause it returns 302 response to client. I want pass request directly to second application instead.
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