Looking for .htaccess file code ?

Discussion in 'HTML & Website Design' started by Charismatic_Verma, Jul 8, 2010.

  1. #1
    Hi,

    I am very much aware of the benefits of redirecting non-www url's to www url's. Now, meta refresh is something that doesn't considered to be a good practice as far as permanent redirect is concerned.

    Another alternative is .htaccess file. At the moment I thoroughly unaware of what are the contents of a .htaccess file. Guys please let me know how should I create .htaccess file from scratch ?

    Looking for positive replies.

    Thanks in Advance :)
     
    Charismatic_Verma, Jul 8, 2010 IP
  2. 123jj

    123jj Member

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    You can use the Google webmaster tool to do that.
     
    123jj, Jul 8, 2010 IP
  3. Charismatic_Verma

    Charismatic_Verma Member

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Great,could you please elaborate a bit ?
     
    Charismatic_Verma, Jul 8, 2010 IP
  4. hadie87

    hadie87 Guest

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use FTP manager
     
    Last edited: Jul 8, 2010
    hadie87, Jul 8, 2010 IP
  5. phpmatt

    phpmatt Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The file is called .htaccess (dot on the front) and it goes in the html root directory. Use the following 3 lines:

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

    Changing yourhost.com to your domain name
     
    phpmatt, Jul 8, 2010 IP
  6. Charismatic_Verma

    Charismatic_Verma Member

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    thank you phpmatt that's what i was looking for...i will let you know after implementing this code.
     
    Charismatic_Verma, Jul 9, 2010 IP
  7. Charismatic_Verma

    Charismatic_Verma Member

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Matt check out the following code -
    This is the exact code I put in the .htaccess file..that's my websit - http://mosymadugba(dot)com
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mosymadugba.com [NC]
    RewriteRule ^(.*)$ http://www.mosymadugba.com/$1 [L,R=301]

    still the non www url is not rediecting towards www url's
     
    Charismatic_Verma, Jul 9, 2010 IP
  8. rive0108

    rive0108 Peon

    Messages:
    119
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is wrong, and thats why it doesnt work.
    Test it here for example:
    http://havocarcade.com

    try this at the top of .htaccess

    note- create/place the .htaccess file in your public_html directory

    like so:
    /public_html/.htaccess/

     
    Last edited: Jul 10, 2010
    rive0108, Jul 10, 2010 IP
  9. Prosac

    Prosac Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    take out [NC] and try that, works fine for me.
     
    Prosac, Jul 12, 2010 IP
  10. coldcoder

    coldcoder Well-Known Member

    Messages:
    954
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #10
    replace
    RewriteCond %{HTTP_HOST} ^mosymadugba.com [NC]
    to
    RewriteCond %{HTTP_HOST} ^mosymadugba.com
    it should be working now
     
    coldcoder, Jul 12, 2010 IP
  11. OnEBoT

    OnEBoT Peon

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Wouldnt you have to remove the ^.
     
    OnEBoT, Jul 12, 2010 IP
  12. rive0108

    rive0108 Peon

    Messages:
    119
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    [NC] means "Case Insensitive", and this is how you set it up in .htaccess ( i am using it on my site myself)
    301 tells the browsers and search engines that this is a permanent redirect
    L means last rule
    ^ Start of line anchor

    For those of you who need more info on URL rewrites see:
    http://www.widexl.com/tutorials/mod_rewrite.html

    This is what he needs to add to .htaccess in /public_html/.htaccess
     
    Last edited: Jul 12, 2010
    rive0108, Jul 12, 2010 IP
  13. Prosac

    Prosac Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I believe [NC] was used in older versions of apache
    I tried both versions in my htaccess ( iam using apache2) and it works only without [NC]
     
    Prosac, Jul 12, 2010 IP
  14. rive0108

    rive0108 Peon

    Messages:
    119
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Hmm i run apache version 2.2.15

    It works fine for me.
     
    rive0108, Jul 13, 2010 IP