Krunal
Krunal

Reputation: 3269

Redirect all older URL ending with .aspx to some URL

I have upgraded a website to a newer mvc version of asp.net. Its already done, however I'm not sure how to redirect older page request ending with aspx to a new URL.

How can I redirect all page requests ending with .aspx to home page URL like www.somedomain.com/

I would like to use rewrite module.

Upvotes: 3

Views: 1058

Answers (1)

saintedlama
saintedlama

Reputation: 6898

For using the rewrite module to redirect everything with an aspx ending to an extension less URL you'll have to first install the URL rewrite module. Best is to install the URL rewrite module with Web Platform Installer

Once installed add the following section to your <system.webServer> section in web.config:

<rewrite>
    <rules>
        <rule name="Redirect to extensionless URL" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*.aspx" />
            <action type="Redirect" url="{R:1}" redirectType="Found" />
        </rule>
    </rules>
</rewrite>

This section defines that any URL matching the pattern *.aspx will be redirected (302) to the extension less URL equivalent. For example a request to /Users.aspx would be redirected to /Users.

In case you would want to redirect all .aspx URLs to some domain you would change the action to this:

<action type="Redirect" url="http://www.somedomain.com" redirectType="Found" />

A 302 redirect is not ideal from a SEO perspective, so I would recommend to test with a 302 redirect and in case everything works as desired switch to a permanent redirect by using the action:

<action type="Redirect" url="{R:1}" redirectType="Permanent" />

Upvotes: 9

Related Questions