如何在每个页面上重写 URL,如下所示:
website.com
到www.website.com
website.com/page1.aspx
到www.website.com/page1.aspx
- 等等
如何在每个页面上重写 URL,如下所示:
website.com
到www.website.com
website.com/page1.aspx
到www.website.com/page1.aspx
好吧,如果我们在谈论 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>
IIS 确实有一个重写模块,可以让你做你想做的事http://www.iis.net/downloads/microsoft/url-rewrite。