Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

301 Redirect for IIS

Tags:

redirect

iis

When I've used Apache, I used .htaccess to redirect a custom path to a certain page.

But my new site is hosted on a Windows server and I cant find any help on setting up redirects for old pages which have been deleted for new pages.

Example. When people visit

[domain]/ValveMonitoring/valveleak.php

They should be forwarded to

[domain]/valve-monitoring/midas-meter.php

Can someone help?

like image 883
ngplayground Avatar asked Jan 27 '12 23:01

ngplayground


2 Answers

  1. In IIS, right click on the file or folder you wish to redirect and select Properties
  2. In the file tab, select "A redirection to a URL"
  3. Enter the url to redirect to
  4. Determine whether you want to do the optional checkboxes (probably will want to check "A permanent redirection for this resource"
  5. Click OK
like image 84
James Kell Avatar answered Sep 27 '22 22:09

James Kell


The rewrite is the way to do this as codechurn points out. Here is an example of what you can stick in the web.config at the root of the site. Its really quite simple:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="TestRewrite">
          <!-- The match is a regex, hence the escaped '.' -->
          <match url="someFile\.php" />
          <action type="Redirect" redirectType="Permanent" url="PHPisSilly.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

You will have to make sure the rewrite module is installed. On Win10 go here to make sure:

Control Panel -> Programs -> Programs and Features -> Turn Windows features on or off -> Internet Information Services -> World Wide Web Services -> Common HTTP Features

And just enable all those options under "Common HTTP Features" and you should be good to go (except maybe Directory Browsing and WebDAV Publishing). Press OK and close.

like image 42
Ian Avatar answered Sep 27 '22 20:09

Ian