MarathonStudios
MarathonStudios

Reputation: 4321

Use Web.Config to redirect a directory to a subdomain

I have a subdirectory (http://example.com/forum) I want to 301-redirect to a new subdomain at htttp://forum.exampple.com. How can I set up a redirect using Web.config and IIS rewrite to send all requests to http://example.com/forum/* to htttp://forum.exampple.com? Thanks!

Upvotes: 3

Views: 13098

Answers (2)

ssri
ssri

Reputation: 1290

To get ride of the querystring being passed to the subdomain can you try like this

RewriteRule ^/forum/(.*)/? http://forum.exampple.com/$1 [R=301,L]

In the rewrite rule if you end with $ it will take the entire url (including the query), so try replacing the $ with /? to get the truncated request without query.

If you are sure your new url doesn't need any querystring you can change it to

RewriteRule ^/forum/(.*)/? http://forum.exampple.com/$1/? [R=301,L]

Upvotes: 0

jman
jman

Reputation: 474

By converting the rule provided by ssri, the rule should look like this in the web.config file:

<rewrite>
  <rules>
    <rule name="your name here" stopProcessing="true">
      <match url="^forum/(.*)$" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="http://forum.exampple.com/{R:1}" />
    </rule>
  </rules>
</rewrite>

Put it between the system.webServer tags.

Upvotes: 6

Related Questions