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

How do I 301 redirect the homepage (and only the homepage) to a different URL?

Discussion in 'BlackHat Lounge' started by tony-raymondo, Oct 4, 2011.

  1. tony-raymondo

    tony-raymondo Junior Member

    Joined:
    Jun 19, 2009
    Messages:
    181
    Likes Received:
    459
    How do I 301 redirect the homepage (and only the homepage) to a different URL?

    I'm using the HTACCESS file.

    For some reason I can't find out how to do this...

    :(

    I am able to redirect subpages.

    I am able to redirect everything.

    But how do i redirect ONLY my HOMEPAGE to a different URL?
     
  2. pureoctane

    pureoctane Newbie

    Joined:
    Aug 19, 2009
    Messages:
    38
    Likes Received:
    9
    have you tried redirecting index.html or index.php? Or however you haomepage is named.
     
  3. milans

    milans Regular Member

    Joined:
    Mar 26, 2011
    Messages:
    370
    Likes Received:
    149
    Code:
    http://serverfault.com/questions/58762/how-to-redirect-root-and-only-root-via-htaccess
     
  4. JenniFranks

    JenniFranks Junior Member

    Joined:
    Jul 26, 2010
    Messages:
    124
    Likes Received:
    44
    Occupation:
    UI Design
    Location:
    Chicago
    Code:
     	RedirectMatch 301 ^/$ http://www.newsite.com/
    
     
  5. G-S-T

    G-S-T Executive VIP Jr. VIP

    Joined:
    Jan 20, 2011
    Messages:
    1,838
    Likes Received:
    8,802
    Occupation:
    Full time IM
    Location:
    Heavy in the game
  6. olimix

    olimix Regular Member

    Joined:
    Jul 21, 2010
    Messages:
    232
    Likes Received:
    71
    Location:
    11h11 brothers
    PHP:
    Options +FollowSymlinks
    RewriteEngine on

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

     
  7. tony-raymondo

    tony-raymondo Junior Member

    Joined:
    Jun 19, 2009
    Messages:
    181
    Likes Received:
    459
    Thanks for all the responses

    But the line must go in the HTACCESS file.

    also, I don't think I have an INDEX.PHP or DEFAULT.HTM or whatever

    So which line do I use above?

    :kabong:
     
  8. G-S-T

    G-S-T Executive VIP Jr. VIP

    Joined:
    Jan 20, 2011
    Messages:
    1,838
    Likes Received:
    8,802
    Occupation:
    Full time IM
    Location:
    Heavy in the game
    send me a link to your site and tell me what you want it to do and i will write you htaccess code :)
     
  9. pavan

    pavan Elite Member

    Joined:
    Mar 30, 2008
    Messages:
    1,603
    Likes Received:
    432
    try this one

    add following lines in your htaccess file

    Code:
    RewriteEngine on
    RewriteRule ^$ http://www.example.com/ [R=301,L]
    replace example.com with different url (where you would like to redirect)
     
    • Thanks Thanks x 1
  10. tony-raymondo

    tony-raymondo Junior Member

    Joined:
    Jun 19, 2009
    Messages:
    181
    Likes Received:
    459
    thanks pavan that worked
     
  11. tony-raymondo

    tony-raymondo Junior Member

    Joined:
    Jun 19, 2009
    Messages:
    181
    Likes Received:
    459
    oh wait a minute

    well i tried both of pavin and olimix solutions

    and they seem to work as "catch-alls"

    .e.g. if someone types example.com/asdf then a redirect rule still is triggered

    i would like example.com to be redirected to google.com

    and any other query example.com/asdf1234 to not trigger any behavior by the htaccess file
     
  12. tony-raymondo

    tony-raymondo Junior Member

    Joined:
    Jun 19, 2009
    Messages:
    181
    Likes Received:
    459
    bumpage
     
  13. milans

    milans Regular Member

    Joined:
    Mar 26, 2011
    Messages:
    370
    Likes Received:
    149
    Just check the url i've sent you. Your exact question is being answered there.
     
  14. RedMango

    RedMango Power Member

    Joined:
    Jul 15, 2010
    Messages:
    518
    Likes Received:
    201
    Location:
    UK
    Obviously I've searched, but can anyone tell me why when I've done a 301 redirect that only the homepage is being redirected and not all other pages? I've done this zillions of times but for some reason two sites only redirect the homepage.

    Also, on another site I'm changing the domain name but keeping the same files from a different site. It is basically a replica of the other domain so I need :

    domain1.com/page-1 to point to domain2.com/page-2

    and so on. But both sites are indexed and 1 isn't directing to 2.

    I've created an htaccess redirection code, I've tried it in WordPress and from Cpanel but the same result each time. Any ideas?
     
  15. G-S-T

    G-S-T Executive VIP Jr. VIP

    Joined:
    Jan 20, 2011
    Messages:
    1,838
    Likes Received:
    8,802
    Occupation:
    Full time IM
    Location:
    Heavy in the game
    trailing slash = all pages in that root.

    So domain.com/ will send everything and its dog to the new url you specify.
     
    • Thanks Thanks x 3
  16. RedMango

    RedMango Power Member

    Joined:
    Jul 15, 2010
    Messages:
    518
    Likes Received:
    201
    Location:
    UK
    It's still doing it. I have a trailing slash.

    If I go into my new domain and click on 'page 2' then it comes with olddomain.com/page-2 not newdomain.com/page-2

    Hmm, need to look at this further.

    Edit: Just changed the 'General' settings in WP to the new domain and it looks sorted. Thanks GST
     
    Last edited: Sep 10, 2013
  17. NgocChinh

    NgocChinh Newbie

    Joined:
    Jul 7, 2009
    Messages:
    32
    Likes Received:
    84
    Use this code:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} olddomain\.com [NC]
    RewriteCond %{REQUEST_URI} ^/$
    Rewriterule ^(.*)$ http://www.newdomain.com/ [L,R=301]
     
  18. craigmoney

    craigmoney Newbie

    Joined:
    Aug 16, 2011
    Messages:
    29
    Likes Received:
    3
    This worked great for me! I even have multiple lines of RedirectMatch 301 for things that aren't the homepage.
     
    Last edited: Oct 31, 2014