从非www重定向到www [英] redirect from non www to www
本文介绍了从非www重定向到www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将我的网站从example.com重定向到www.example.com
I want to redirect my site from example.com to www.example.com
推荐答案
Option 1: Redirecting example.com/dir/anypage.html to www.example.com/dir/anypage.html (same page)
Use this format if you want a request for any URL at example.com to redirect to the same page at www.example.com. (If you want to redirect to the home page of www.example.com, see option 2 below.)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [nocase]
RewriteRule ^(.*) http://www.example.com/
1 [last,redirect = 301]
1 [last,redirect=301]
Option 2: Redirecting example.com/dir/anypage.html to the www.example.com home page
Use this format if you want a request for any URL at example.com to redirect to the home page of www.example.com. (If you want to redirect to the same page at www.example.com, see option 1 above.)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [nocase]
RewriteRule ^(.*) http://www.example.com/ [last,redirect=301]
通过iis中的microsoft web platform安装程序安装url rewrite 2.0,并在Web配置文件中添加以下代码特定领域:
Install url rewrite 2.0 via microsoft web platform installer in your iis and add the following code in the web config file of particular domain:
<system.webserver>
<rewrite>
<rules>
<rule name="Redirect domain.com to www" patternsyntax="Wildcard" stopprocessing="true">
<match url="*" />
<conditions logicalgrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="abc.com" />
<add input="{HTTP_HOST}" pattern="ABC.COM" />
<add input="{HTTP_HOST}" pattern="Abc.com" />
<add input="{HTTP_HOST}" pattern="ABc.com" />
<add input="{HTTP_HOST}" pattern="aBc.com" />
</conditions>
<action type="Redirect" url="http://www.abc.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webserver>
这篇关于从非www重定向到www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文