Help with Code for 301 redirct

Discussion in 'Programming' started by lakelover339, Jul 17, 2010.

  1. #1
    I am not a coder, so I am hoping someone can check over what I am about to do (found a variety of code online and got some from Hostgator)

    I want to redirect my www domain name to the non www
    I also want to redirect the /index.htm page to non , though probably less important

    This is the code I want to put in the .htaccess file:


    RewriteCond %{HTTP_HOST} ^www.mydomain.com$

    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

    AND

    RewriteCond %{THE_REQUEST} ^.*mydomain.com/index.htm\ HTTP/

    RewriteRule ^(.*)mydomain.com/index.htm$ /$1 [R=301,L]


    Do I need the following stuff? and if so do I need to change anything?


    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301,QSA,L]


    Thanks!
     
    Last edited: Jul 17, 2010
    lakelover339, Jul 17, 2010 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Try:

    RewriteCond %{HTTP_HOST} ^www.mydomain.com$
    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} ^/index.htm$
    RewriteRule ^(.*)$ http://mydomain.com/ [R=301,L]
     
    rainborick, Jul 17, 2010 IP
  3. lakelover339

    lakelover339 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What about the Rewrite Engine On, etc?

    Does anyone know how the 'redirect' in the General settings panel of Wordpress affects or interacts with the htacess file? I would be having them say the same thing, but since wordpress 'redircts' I cannot see a way to test the code I put in htacces file.
     
    lakelover339, Jul 29, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    note, wordpress will always redirect to its homepage set in db
     
    gapz101, Aug 7, 2010 IP
  5. lakelover339

    lakelover339 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Does anyone know this?
    Do I need the following stuff? and if so do I need to change anything?

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301,QSA,L]
     
    lakelover339, Aug 7, 2010 IP