How to Force or Remove WWW in a DotNetNuke URL

DNN > How To
How to Force or Remove WWW in URL

If you would like to force or remove the WWW in the URL for your domain name for SEO or SSL reasons you may do so using the steps below. The methods vary depending on which version of Windows Server your site is hosted on. If you are unsure of this you can contact our support department and they will be able to tell you.

Forcing WWW

Site Hosted on Server 2008 (IIS 7) or Server 2012 (IIS 8)

All Versions of DotNetNuke

  1. Connect to your site's web.config file.  If you are unsure of how to do this please refer to our How to Access Your Web.Config article.
  2. Scroll down until you find the <system.webserver> or </handlers> line and just below it, press enter to add a new line.
  3. Paste the following code at the new line:
    <rewrite>
      <rules>
       <clear />
        <rule name="WWW Rewrite" enabled="true">
          <match url="(.*)" />
            <conditions>
              <add input="{HTTP_HOST}" negate="true" pattern="^www\.(.*)$" />
            </conditions>
            <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  4. Save the web.config.

Site Hosted on Server 2003 (IIS 6)

DotNetNuke 6.x and 7.x

Forcing the WWW URL can be done within DNN in 6.x by assigning a default URL of www.domain.com and forcing all requests to the default URL.  If you have not added www.domain.com as an alias within DNN you may do so by following the DNN 6 instructions in How to Create a Portal Alias in DotNetNuke.
  1. Log in to your DotNetNuke install as either a Host or Admin user.
  2. Navigate to Admin > Site Settings.
  3. Click the Advanced Settings tab.
  4. Expand Site Aliases.
  5. In SiteAlias Mapping Mode select the Redirect radio button.
  6. Click Update.
  7. When the page reloads scroll back down to Site Aliases.
  8. Under Default Alias use the drop down menu to select the www.domain.com alias.
  9. Click Update.

DotNetNuke 4.x and 5.x

  1. Connect to your site via FTP. If you are unsure of how to do this please refer to How to Use FTP.
  2. Navigate to /httpdocs/CUSTOMIZATIONS/SiteHeader.aspx.resources in your FTP client.
  3. Open the SiteHeader.aspx.resources in Notepad and paste the following code into it:
    <script runat="server" language="VB">
        Private Sub CUSTOM_PageLoad_ForceWWW(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim RequestURI = Request.Url
                If Not RequestURI.Host.ToLower().StartsWith("www.") Then
                Dim NewURL = RequestURI.Scheme + "://www." + RequestURI.Host + Request.RawUrl
                Response.Status = "301 Moved Permanently"
                Response.AddHeader("Location", NewURL)
            End If
        End Sub
    </script>
  4. Save the file.

Remove WWW

Site Hosted on Server 2008 (IIS7) or Server 2012 (IIS 8)

All Versions of DotNetNuke

  1. Connect to your site's web.config file.  If you are unsure of how to do this please refer to our How to Access Your Web.Config article.
  2. Scroll down until you find the <system.webserver> or </handlers> line and just below it, press enter to add a new line.
  3. Paste the following code at the new line:
    <rewrite>
      <rules>
        <rule name="Remove WWW" stopProcessing="true">
          <match url=".*" ignoreCase="true" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
          </conditions>
          <action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Temporary" />
        </rule>
      </rules>
    </rewrite>
  4. Save the web.config

Site Hosted on Server 2003 (IIS 6)

DotNetNuke 6.x and 7.x
Removing the WWW URL can be done within DNN in 6.X by assigning a default URL of [domain.com] and forcing all requests to the default URL.

  1. Log in to your DotNetNuke install as either a Host or Admin user.
  2. Navigate to Admin > Site Settings.
  3. Click the Advanced Settings tab.
  4. Expand Site Aliases.
  5. In SiteAlias Mapping Mode select the Redirect radio button.
  6. Click Update.
  7. When the page reloads scroll back down to Site Aliases.
  8. Under Default Alias use the drop down menu to select the [domain.com] alias.
    • If the [domain.com] alias isn't listed, it will need to be added to the database's portalalias table.
  9. Click Update.

DotNetNuke 4.x and 5.x

  1. Connect to your site via FTP. If you are unsure of how to do this please refer to our article on How to Use FTP.
  2. Navigate to /httpdocs/CUSTOMIZATIONS/SiteHeader.aspx.resources in your FTP Client.
  3. Open the SiteHeader.aspx.resources in Notepad and paste the following code into it:
    <script runat="server" language="VB">
        Private Sub CUSTOM_PageLoad_ForceNoWWW(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim RequestURI = Request.Url
            If RequestURI.Host.ToLower().StartsWith("www.") Then
                Dim NewURL = RequestURI.Scheme + "://" + RequestURI.Host.SubString(4) + Request.RawUrl
                Response.Status = "301 Moved Permanently"
                Response.AddHeader("Location", NewURL)
            End If
        End Sub
    </script>
  4. Save the file.
 

 

 

 

Add Feedback