IIS301重定向 URL Rewrite

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

IIS URL Rewrite – rewriting non-www to www
If you’re using IIS 7.0 (or 7.5), URL Rewrite is a valuable tool, well worth installing and using.
One common use of URL Rewrite is redirecting to . Many people are doing this for search engine optimization (SEO) so that search engines only see the one site, rather than two sites. The goal is to set a permanent 301 redirect.
You can download URL Rewrite from
/expand/URLRewrite. For this walkthrough and screenshots I’ll use URL Rewrite 2.0 RC1, but everything that I’ll cover also works for version 1.0 and 1.1.
URL Rewrite works at the global level, or site level (or application level for that matter). Where you apply it is really up to how you manage your server. Either will work for a domain name redirect like this.
You can choose to create the rules using IIS Manager, or using a text editor and updating web.config directly. I’ll show both, starting with IIS Manager.
Let’s get started. First, open IIS Manager and double-click on the “URL Rewrite” icon.
Next, click on “Add Rules…” from the Actions pane.
Here you’ll have a choice from a few wizard options, and with URL Rewrite 2.0 you can also create outbound rules. Create a Blank rule (inbound rules).
Give your rule a good friendly “Name”.I’ll call mine “Redirect to www”.
In the “Using”dropdown box you can choose between Regular Expressions and Wildcards. Use wildcards if you aren’t familiar with regular expressions since they are much more intuitive. However, if you later need to create more complex rules, regex may be necessary.
For this demo select Wildcards. However, I’ll include instructions for those wanting to use regular expressions.
Enter *for the “Pattern”. That means anything qualifies. We’ll use a condition later instead of matching to the URL. (for Regular Expressions, use .*).
Now expand the “Conditions” section and click “Add”.In the “Add Condition” dialogue enter the following:
Condition input: {HTTP_HOST}
Check if input
Matches the Pattern
string:
Pattern:
(for regex, enter ^$)
Ignore case: checked
Click OK.
Finally, it’s time to set the Action.
In the Action secti on make sure that the “Action Type” is set to Redirect.
For the “Action Properties”, enter /{R:0}. The {R:0} retains the existing URL so if someone typed something like /aboutus it would retain the aboutus as it adds the www.
Be sure that the “Append query string” remains checked so that the querystring part is also retained.
Also, be sure that the “Redirect Type” is set to Permanent (301), which is what the search engines like. This tells the search engines to do a permanent redirect, use the new location and ignore the previous location.
Finally, Apply the rule and test!
Using a Text Editor
You can also create this rule manually by adding the following to your site’s web.config (or applicationHost.config if you set this at the server level).
In the <system.webServer> section of your web.config, add the following:
Wildcards
<rewrite>
<rules>
<rule name="Redirect to www"patternSyntax="Wildcard"
stopProcessing="true">
<match url="*"/>
<conditions>
<add input="{HTTP_HOST}"pattern=""/>
</conditions>
<action type="Redirect"url="/{R:0}"/>
</rule>
</rules>
</rewrite>
Save and you should be set.
Or, if you prefer Regular Expressions, use this instead:
Regular Expressions
<rewrite>
<rules>
<rule name="Redirect to www"patternSyntax="ECMAScript"
stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}"pattern="^$"/>
</conditions>
<action type="Redirect"url="/{R:0}"/>
</rule>
</rules>
</rewrite>
This is just the start to great SEO, but it’s a common step and one that I hope you find helpful.
/owscott/archive/2009/11/27/iis-url-rewrite-rewriting-non-www-to-www.asp x
/downloads/en/details.aspx?FamilyID=c8d3e2a4-5d14-434b-a067-39a6 fb8b9311
/downloads/en/details.aspx?FamilyID=1b8c7bd8-8824-4408-b8fc-49dc 7f951a00。

相关文档
最新文档