Redirect all requests to one or more directories to another directory. If you are doing this because you are restructuring a website and you have existing URLs which have been indexed by search engines, then for SEO purposes this redirect should be Permanent (301).

Redirect and preserve original path

To redirect all requests to one or more directories to a single directory, add the following rule to web.config’s <rules> section:

<system.webServer>
	<rewrite>
		<rules>
			<rule name="Redirect to /resources/ directory" stopProcessing="true">
			    <match url="^(articles|books|videos)(.*)" ignoreCase="true" />
			    <action type="Redirect" url="https://www.example.com/resources/{R:2}" redirectType="Permanent" appendQueryString="true" />
			</rule>
		</rules>
	</rewrite>
</system.webServer>

This would cause all requests to content in the /articles/, /books/, and /videos/ directories to be redirected to https://www.example.com/resources/, preserving the paths within those original directories (say you’ve just moved all content from those directories directly into /resources/).

If you are doing this because you are restructuring a website and have existing URLs which have been indexed by search engines, then for SEO purposes this redirect should be Permanent (301).

Why Lose Memories?

Redirect and ignore original path

There may be times where you simply want to redirect all requests from one or more directories to a new directory and do not want the original paths within those directories preserved, for example if you want all requests to be redirected to the default page of the new directory.

If so, use the following rule:

<system.webServer>
	<rewrite>
		<rules>
			<rule name="Redirect to /resources/ default page" stopProcessing="true">
			    <match url="^(articles|books|videos).*" ignoreCase="true" />
			    <action type="Redirect" url="https://www.example.com/resources/" redirectType="Permanent" appendQueryString="true" />
			</rule>
		</rules>
	</rewrite>
</system.webServer>

This would cause all requests to content in the /articles/, /books/, and /videos/ directories to be redirected to https://www.example.com/resources/ disregarding the original request’s URI.