htaccess redirects unnecessary?

Discussion in 'Site & Server Administration' started by fine0023, Sep 7, 2012.

  1. #1
    I have the following code in my htaccess:
    #if the domain is not www.mydomain.com
    RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
    #redirect to www.mydomain.com
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    Code (markup):
    I believe the purpose of this is for redirecting the non-www domain to the www domain (I'll call this the 'non-www code').

    I was wondering if I even need this code because I have www.mydomain.com set as my hard canonical name, which I think is supposed to redirect aliases such as mydomain.com automatically (without having to code anything in htacess). So could I just do away with this code completely?

    I also have the following code:
    #leave this rule in place, but after the one above to handle the home page
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
    RewriteRule ^(.*)index\.html$ http://www.mydomain.com/$1 [R=301,L]
    Code (markup):
    I believe this is in there to redirect http://www.mydomain.com/index.html to http://www.mydomain.com/ (I'll call this the 'index.html' code).

    I'm not sure if I could also also remove the 'index.html code' using the same logic that I gave above for getting ride of the 'non-www code'? Can I remove only the 'non-www code' and just leave the 'index.html code' by itself?
     
    fine0023, Sep 7, 2012 IP
  2. cesurasean

    cesurasean Active Member

    Messages:
    269
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Head over to #httpd on irc.freenode.net using IRC. They'll be sure to help you.
     
    cesurasean, Feb 23, 2013 IP
  3. celestiasybila

    celestiasybila Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    The purpose of these redirect is to tell the search engines that it is the same site to avoid duplicate content confusions, and make sure that the users/visitors go to the standard URL. So you can put multiple redirects to the standard URL of your domain.
     
    celestiasybila, Feb 27, 2013 IP