如何在每个页面上重写URL,如下所示:
website.com
至www.website.com
website.com/page1.aspx
至www.website.com/page1.aspx
答案 0 :(得分:2)
好吧,如果我们正在谈论apache,那么在.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website\.com [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]
对于IIS和web.config,请使用
<rewrite>
<rules>
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.website\.com$" negate="true" />
</conditions>
<action type="Redirect" url="{MapSSL:{HTTPS}}www.website.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapSSL" defaultValue="OFF">
<add key="ON" value="https://" />
<add key="OFF" value="http://" />
</rewriteMap>
</rewriteMaps>
</rewrite>
答案 1 :(得分:0)
IIS确实有一个重写模块,可以让你做你想做的事情http://www.iis.net/downloads/microsoft/url-rewrite。