Redirecting root to folder

Discussion in 'Site & Server Administration' started by MattUK, Jan 11, 2008.

  1. #1
    I have a site where I'm trying to 301 all the root traffic to a folder.

    I've tried,

    RewriteEngine On
    RewriteBase /
    
    RewriteRule (.*)$ http://www.domain.com/forums/$1 [R=301,L]
    Code (markup):
    But this end up redirecting to,

    http://www.domain.com/forums/forums/forums/forums/forums/forums/ etc etc etc

    Anyone solved this before?
     
    MattUK, Jan 11, 2008 IP
  2. TheBiaatch

    TheBiaatch Peon

    Messages:
    435
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes,

    Remove the index.html file in your root and make a index.php containing this:

    <?php header("location:/forum/"); ?>
    Code (markup):
    3

    Hope this helped you out!
     
    TheBiaatch, Jan 11, 2008 IP
  3. MattUK

    MattUK Notable Member

    Messages:
    6,950
    Likes Received:
    377
    Best Answers:
    0
    Trophy Points:
    275
    #3
    Is it possible to do this without removing the index file? I'm trying to keep it there for a reason
     
    MattUK, Jan 11, 2008 IP
  4. TheBiaatch

    TheBiaatch Peon

    Messages:
    435
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You might be able to use this;

    <meta http-equiv="Refresh" content="0; url=/forum/">
    Code (markup):
    0 is the number of seconds you want it to load after it redirects to your forum...

    Let me know if this worked...
     
    TheBiaatch, Jan 11, 2008 IP
    MattUK likes this.
  5. MattUK

    MattUK Notable Member

    Messages:
    6,950
    Likes Received:
    377
    Best Answers:
    0
    Trophy Points:
    275
    #5
    Id' rather use a 301 redirect than a meta refresh, it can cause problems with SEO.
    I appreciate your help though :) It's frustrating as I have seen this done before with a 301, I just can't for the life of me remember how it was done!
     
    MattUK, Jan 11, 2008 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    The easy solution is to turn RewriteEngine off in the sub-directory, but that's usually not an option.

    This may work for you though, or at least be close.
    RewriteCond %{REQUEST_URI} !^/?forum
    RewriteRule ^(.+)?$ http://domain.com/forum/$1 [QSA,R=301]
    Code (markup):
     
    joebert, Jan 11, 2008 IP
  7. MattUK

    MattUK Notable Member

    Messages:
    6,950
    Likes Received:
    377
    Best Answers:
    0
    Trophy Points:
    275
    #7
    I managed to find a solution,

    RedirectMatch permanent ^/$ http://mydomain.com/php/index.php
    Code (markup):
    This worked fine :)
     
    MattUK, Jan 11, 2008 IP
  8. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #8
    You don't need to catch anything other than a directory listing or index ?
     
    joebert, Jan 11, 2008 IP