redirecting homepage

Discussion in 'Apache' started by goppss, Oct 6, 2009.

  1. #1
    I've have getting hints on the internet that one should prevent having multiple URLs of the index page as in the following:

    http:/website.com
    http:/www.website.com
    http:/www.website.com/
    http:/www.website.com/index.html
    http:/website.com/index.html

    What would i have to do in order to have all listed URLs pointing to http:/website.com/, and is the URL I've selected the best?

    thanks in advance.
     
    goppss, Oct 6, 2009 IP
  2. goppss

    goppss Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have the following in my .htaccess file would it do the trick?

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^website.com$ [NC]
    RewriteRule ^(.*)$ http://website.com/$1 [L,R=301]
     
    goppss, Oct 6, 2009 IP
  3. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That first part would redirect everything that is not website.com to website.com which would make:

    www.website.com => website.com
    www.website.com/index.html => website.com/index.html
    www.website.com/somepage.html => website.com/somepage.html

    In order to redirect index.html to / you will also need:

    RewriteRule ^index\.html$ / [R=301,L]
    Code (markup):
    website.com and website.com/ are already seen as the same thing.
     
    chadsmith, Oct 8, 2009 IP