12

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?

mybrave
  • 1,662
  • 3
  • 20
  • 37
ngplayground
  • 20,365
  • 36
  • 94
  • 173

3 Answers3

6

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.

Ian
  • 4,169
  • 3
  • 37
  • 62
  • This should have been the accepted answer. Just a quick edit of the web.config and none of this IIS interface attempt. That was confusing as. – Fandango68 Jun 02 '22 at 01:55
6
  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
James Kell
  • 166
  • 1
  • 3
  • My problem with this is I dont have any of the old files or folders anymore. With Apache/htaccess I could just write a 301 redirect with a path... – ngplayground Jan 30 '12 at 08:17
  • You can always put in an empty file or folder with the same name as the old one and then redirect it. – James Kell Jan 30 '12 at 17:40
  • I found out how to do it. Open up IIS Manager and click the domain I want to focus on. Then open up URL Rewrite and past my old path into the top input box and then the new path in the 2nd input – ngplayground Feb 02 '12 at 16:16
  • Is this possible if you only have FTP or web access to the Server? – tristanbailey Apr 30 '14 at 14:42
3

The easiest way to do this in IIS7 and beyond is to install the URL Rewrite module. Please see the following for documentation: http://learn.iis.net/page.aspx/734/url-rewrite-module

You can download the URL Rewrite Module for IIS 7 from here and follow the prompts to install.

codechurn
  • 3,870
  • 4
  • 45
  • 65
  • 17
    You should explain how to do it in IIS. if the link goes down this answer is worth nothing... – Yann Chabot Jul 27 '17 at 16:33
  • @YannChabot there is full self-explanatory video by the link. Why do you need anything else? – Hardoman Aug 04 '20 at 11:02
  • 3
    @Hardoman links are dangerous answers because if the link ever goes down, then this answer is worth nothing, if you take critical parts of the videos and paste them in answers, then if the link goes down the answer lives forever. – Yann Chabot Aug 05 '20 at 16:10
  • 1
    I'm pretty sure people will be able to figure out how to install the Rewrite Module even if this link goes down – lockstock Mar 14 '23 at 23:09