简体   繁体   中英

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!

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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM