0

如何在每个页面上重写 URL,如下所示:

  • website.comwww.website.com
  • website.com/page1.aspxwww.website.com/page1.aspx
  • 等等
4

2 回答 2

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>
于 2013-05-06T01:16:15.180 回答
0

IIS 确实有一个重写模块,可以让你做你想做的事http://www.iis.net/downloads/microsoft/url-rewrite

于 2013-05-06T01:24:39.857 回答