1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can someone teach me exactly how to create this htaccess file

Discussion in 'White Hat SEO' started by Techxan, Nov 21, 2013.

  1. Techxan

    Techxan Elite Member

    Joined:
    Dec 7, 2011
    Messages:
    3,093
    Likes Received:
    3,585
    Occupation:
    Local SEOist
    Location:
    TEXAS (you have to yell, its the law.)
    I have a site that still shows both the www, and non www versions. I have put the preferred domain nmae in GWMT, but I can still go to the site with or without www. The non www version is not redirecting to the www version. In addition to that, when I create a sitemap, I see these pages.

    www.sitename.com
    sitename.com
    www.sitename.com/index.html.

    Can someone teach me how to create an htacess file that will 301 redirect the non www version of the site to the www version, AND the www.sitename.com/index.html page to the www.sitename.com page?

    I have ftp access, but not cPanel access, so doing it in the cPanel is not an option.
     
  2. lonhot2000

    lonhot2000 Newbie

    Joined:
    Sep 23, 2013
    Messages:
    19
    Likes Received:
    3
    Here you go (remove dashes in RewriteRule url):

    RewriteEngine on
    RewriteBase /
    # redirect non-www to www
    RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
    RewriteRule (.*) h-t-t-p-:-/-/-w-w-w.yoursite.com/$1 [R=301,L]
    # redirect index.html page to the root domain
    RewriteRule ^index\.html$ / [R=301,L]
     
    Last edited: Nov 21, 2013
  3. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    8,836
    Likes Received:
    7,450
    Occupation:
    ZLinky2Buy SEO Services
    Location:
    ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
    Home Page:
    Code:
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\.sitename\.com$ 
    RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
    
    Needless to say it requres the mod_rewrite module activated on your host.
     
  4. MaximumAchievement

    MaximumAchievement Jr. VIP Jr. VIP

    Joined:
    Aug 9, 2013
    Messages:
    120
    Likes Received:
    6
    Code:
    [TABLE]
    [TR]
    [TD="class: votecell"][/TD]
    [TD="class: answercell"]                  [B]JavaScript[/B]
    
      <script language="javascript">
        window.location.href = "http://example.com"
    </script>  [B]
    
    
                      Meta tag[/B]
    
      <meta http-equiv="refresh" content="0;url=http://example.com">      [/TD]
    [/TR]
    [/TABLE]