开发者

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 subd开发者_如何转开发omain 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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜