Summary

Learn how to use web.config to redirect an index file to your root. Windows hosting only.

What does it do?

This rule redirects the index file to your website root. The rule can be added to the web.config file and works with sites hosted on our Windows servers.

For example:

http://www.domain.com/index.php

Is automatically redirected to:

http://www.domain.com

Why use this rule?

This web.config rule reduces the chances of duplicate results appearing in the search engines for the same page, improve your sites ranking. This is known as URL canonicalization, or canonical URLs.

Example web.config index redirect

Your web.config file is a critical file so take a backup before making any edits. This way you can restore the file quickly should something going wrong.

To use this rule, add the following code to your existing web.config file.

<rewrite>
	<rules>
	<clear></clear>
		<rule name="redirect index.asp" stopProcessing="true">
			<match url="^(\w*/)?index\.php"></match>
			<conditions>
			<add input="{HTTP_HOST}" pattern="^domain\.com$"></add>
			</conditions>
			<action type="Redirect" url="http://domain.com/{R:1}"></action>
		</rule>
	</rules>
</rewrite>