1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

.htaccess to redirect to a new domain EXCEPT homepage

Discussion in 'Apache' started by taulath, Jan 22, 2007.

  1. #1
    I'm looking to 301/302 all requests to a domain1 to domain2, except when someone requests the homepage of domain1 (eg www.domain1.com, www.domain1.com/ or www.domain1.com/index.html), in which case a file on domain1 will be served.

    Any solutions?

    Here's my (non working) attempt..

    RewriteEngine on

    RewriteRule ^$ index.php [L,NC]
    RewriteRule ^/$ index.php [L,NC]
    RewriteRule ^/index.html$ index.php [L,NC]

    RewriteRule ^/(.+) http://www.domain2.com/$1 [L,R=301,NC]
     
    taulath, Jan 22, 2007 IP
  2. stuey

    stuey Peon

    Messages:
    160
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is pretty unusual, but depending upon the amount of URL's you have, it might be best to set up all of the redirects as separate entities, minus the home page.

    e.g.

    redirect 301
    redirect 301
    redirect 301
    redirect 301
    redirect 301

    I presume that the links will not be growing so you could list all of your filenames (drop the index file - index.html) from your home directory and allow indexes- this should only take you a second to do) copy them into excel and write a concatenate script that would prefix the filenames with "redirect 301". In fact, i've done one for you - so you understand.

    This will save you a bucketload of time!
     

    Attached Files:

    stuey, Jan 22, 2007 IP
  3. taulath

    taulath Peon

    Messages:
    290
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks so much for your time Stuey! That's a neat solution, but unfortunatley the domain in question has over 20,000 pages of which most are dynamic and generated from the database :eek:

    Although I could use my Google sitemap file to provide the static urls in a handy list if theres no alternative
     
    taulath, Jan 22, 2007 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)$ http://www.domain.com/$1/ [R=301,L]
    RewriteRule ^index.php$ index.php [L]
    RewriteRule ^$ index.php [L]
     
    Nintendo, Jan 23, 2007 IP
  5. taulath

    taulath Peon

    Messages:
    290
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nintendo, you are indeed King - but in this case of the .htaccess

    Cheers mate :)
     
    taulath, Jan 23, 2007 IP