0

How can I rewrite URLs on every page, as follows:

  • website.com to www.website.com
  • website.com/page1.aspx to www.website.com/page1.aspx
  • etc.
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179

2 Answers2

1

well if we are talking apache, then in .htaccess

RewriteEngine   on
RewriteCond %{HTTP_HOST} ^website\.com [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]

for IIS and web.config, go with

<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>
Drew
  • 24,851
  • 10
  • 43
  • 78
0

IIS does have a rewrite module that will allow you to do what you want http://www.iis.net/downloads/microsoft/url-rewrite.

iamkrillin
  • 6,798
  • 1
  • 24
  • 51