Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS rewrite rule to redirect specific domain url to different url on same domain

I simply want an IIS 7.5 rewrite rule to redirect http://www.domain.com/url1 to http://www.domain.com/url2 (same domain). This can be achieved by:

<rule name="Redirect url" enabled="true" stopProcessing="true">
    <match url="^url1" />
    <action type="Redirect" url="http://www.domain.com/url2"
      appendQueryString="false" redirectType="Permanent" />
</rule>

However, this website listens to several domains, thus above becomes a global rule for all domains. How do I make this specific to domain.com? Have tried changing match url and adding conditions but cannot get it to work. Thanks.

like image 319
James Barry Avatar asked Mar 04 '14 20:03

James Barry


People also ask

How do I redirect one URL to another URL in IIS?

In the Home pane, double-click HTTP Redirect. In the HTTP Redirect pane, check the box to redirect requests and enter the destination URL. You can optionally specify any of the following options: Configure the redirection destination to be the exact destination as entered.

Can I redirect a domain to a specific URL?

Under the Domain category, choose the Redirects menu. You'll see the Create a Redirect section. Here, you'll need to fill in which URL you want to Redirect and where you want it to Redirect To. Make sure your information is correct and choose the right connection protocol – HTTP or HTTPS.


1 Answers

I got it to work this way:

<rule name="Redirect url1" stopProcessing="true">
     <match url="^url1$" />
     <conditions>
          <add input="{HTTP_HOST}" pattern="^(www.)?domain.com$" />
     </conditions>
     <action type="Redirect" url="http://www.domain.com/url2"
      appendQueryString="false" redirectType="Permanent" />
</rule>
like image 125
James Barry Avatar answered Sep 19 '22 13:09

James Barry