.htaccess to redirect domain.com to domain.com/blog ?

Discussion in 'Apache' started by andrewgjohnson, Jul 29, 2008.

  1. #1
    Hi here is my current .htaccess file:


    options +followsymlinks
    rewriteengine on
    
    rewritecond %{HTTP_HOST} ^domain.com [nc]
    rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
    
    
    
    rewriterule ^images/posters/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/ /image.php?type=posters&movie=$1&id=$2 [L]
    
    
    
    rewriterule ^admin/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?page=admin&admin=$1&sub=$2 [L]
    rewriterule ^admin/([A-Za-z0-9-]+)/?$ /index.php?page=admin&admin=$1 [L]
    
    rewriterule ^blog/([A-Za-z0-9-]+)/?$ /index.php?page=blog&post=$1 [L]
    
    rewriterule ^trailers/(new|a-z|most-watched)/?$ /index.php?page=trailers&list=$1 [L]
    rewriterule ^trailers/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?page=trailers&movie=$1&trailer=$2 [L]
    rewriterule ^trailers/([A-Za-z0-9-]+)/?$ /index.php?page=trailers&movie=$1 [L]
    
    rewriterule ^galleries/(new|a-z|most-viewed)/?$ /index.php?page=galleries&list=$1 [L]
    rewriterule ^galleries/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?page=galleries&movie=$1&gallery=$2 [L]
    rewriterule ^galleries/([A-Za-z0-9-]+)/?$ /index.php?page=galleries&movie=$1 [L]
    
    rewriterule ^movies/(coming-soon|a-z|recently-added)/?$ /index.php?page=movies&list=$1 [L]
    rewriterule ^movies/([A-Za-z0-9-]+)/?$ /index.php?page=movies&movie=$1 [L]
    
    rewriterule ^actors/([A-Za-z0-9-]+)/?$ /index.php?page=artist&artist=$1&type=actor [L]
    rewriterule ^directors/([A-Za-z0-9-]+)/?$ /index.php?page=artist&artist=$1&type=director [L]
    rewriterule ^writers/([A-Za-z0-9-]+)/?$ /index.php?page=artist&artist=$1&type=writer [L]
    
    rewriterule ^posters/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php?page=poster&movie=$1&id=$2 [L]
    rewriterule ^posters/([A-Za-z0-9-]+)/?$ /index.php?page=poster&movie=$1 [L]
    
    rewriterule ^([A-Za-z0-9-]+)/?$ /index.php?page=$1 [L]
    Code (markup):
    Only thing I want changed is when someone goes to www.domain.com that they be redirected to www.domain.com/blog/

    PLEASE HELP!
     
    andrewgjohnson, Jul 29, 2008 IP
  2. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #2
    You can just use the redirect option in cpanel to do this. It is easier since you only want to redirect domain.com to domain.com/blog.
     
    proxywhereabouts, Jul 29, 2008 IP
  3. andrewgjohnson

    andrewgjohnson Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    I'd kind of like to know HOW it is being done rather than rely on cpanel...
     
    andrewgjohnson, Jul 29, 2008 IP
  4. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this solution:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/blog/$1 [R=301]
     
    Bohol, Jul 30, 2008 IP
  5. andrewgjohnson

    andrewgjohnson Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Wouldn't that take EVERYTHING and append /blog/ to it? I'm just wanting the root domain to redirect to /blog/ so no one can ever go to www.domain.com without them being transferred.

    Just to give you an idea of the spec: I'm working on a movie website that has 4 main headers: blog, trailers, movies, galleries. Each of these have a root address: domain.com/blog/, domain.com/trailers/, domain.com/movies/, & domain.com/galleries/. The main draw (or at least my goal for it to be) is going to be the blog so when someone comes to the site I want that the blog to be what they see. Currently it is via PHP includes, however I also want the URL to reflect what they are looking at.
     
    andrewgjohnson, Jul 30, 2008 IP
  6. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If it doesn't work, just remove the suggested redirection code and let's try another solution. Kindly provide us then your feedback.
     
    Bohol, Jul 30, 2008 IP
  7. andrewgjohnson

    andrewgjohnson Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    It does what I said it did... my unsureness was meant as a courtesy, what was going to happen was fairly obvious.
     
    andrewgjohnson, Jul 31, 2008 IP
  8. blowingideas

    blowingideas Peon

    Messages:
    642
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    blowingideas, Jul 31, 2008 IP
  9. andrewgjohnson

    andrewgjohnson Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    Hmm I actually had a friend suggest that and it is timing out and ending up on this URL:

    http://www.filmfollower.com/blog/bl...blog/blog/blog/blog/blog/?page=blog&post=blog

    Something is obviously causing the server to think that all URLs should be following this rule, even if I go to a different URL such as:

    http://www.filmfollower.com/trailers/

    and it ends up going to:

    http://www.filmfollower.com/blog/bl...og/blog/blog/trailers?page=blog&post=trailers

    Ugh, I hate not knowing where to even begin with this problem :/
     
    andrewgjohnson, Jul 31, 2008 IP
  10. andrewgjohnson

    andrewgjohnson Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    Not sure if anyone cares but I solved it and here is the line that served as the solution:

    
    redirectmatch 301 ^/$ http://www.filmfollower.com/blog/
    
    Code (markup):
    I'm thinking that dollar sign is what I was missing from day one. But whatever, I still don't get htaccess but all's well that ends well.
     
    andrewgjohnson, Jul 31, 2008 IP
  11. Bohol

    Bohol Peon

    Messages:
    2,680
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hi Andrew,

    It's good to hear that you were able to fix the issue. Cheers!
     
    Bohol, Aug 1, 2008 IP
  12. snvc

    snvc Peon

    Messages:
    194
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Great to know it too that you fixed the issue.
     
    snvc, Aug 23, 2008 IP