Announcement

Collapse
No announcement yet.

How to redirect www to root domain (non-www)?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to redirect www to root domain (non-www)?

    I want to redirect www to my root domain, so I have written the following lines in the .htaccess file.

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www.mydomian.com [NC]
    RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
    But code doesn't work.

    Is there another way I can redirect www to the root domain?

  • #2
    Which web server are you using?
    If you are using IIS on Windows, then you have to use IIS URL Rewrite.

    Comment


    • #3
      I am using shared hosting.
      Should I contact the web host?

      Comment


      • #4
        By using the following code you can be done redirecting www to root domain(non-www).

        $HTTP["host"] =~ "^www\.(.*)$" {
        url.redirect = ( "^/(.*)" => "http://%1/$1" )
        }
        Make sure the mod_redirect module is installed on your server to work this rule. You need to add the code at the top of the config file before other redirect/rewrite rules.

        Comment

        Working...
        X