How to redirect from folder to main page?

Discussion in 'Apache' started by Johnburk, Apr 4, 2007.

  1. #1
    Johnburk, Apr 4, 2007 IP
  2. abdussamad

    abdussamad Active Member

    Messages:
    543
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    in the subfolder do a 301 redirect:

    redirect 301 /path/to/subfolder/ http://domain.com
     
    abdussamad, Apr 5, 2007 IP
  3. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you. I tried redirect, the problem with that is that all files have to moved to the new location. How is it possible to do this (modrewrite?) and not have to moved all the files, so that PR stays 4?
     
    Johnburk, Apr 5, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    In a domain.com/site/blog/.htaccess file, put:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    Code (markup):
     
    rodney88, Apr 5, 2007 IP
  5. abdussamad

    abdussamad Active Member

    Messages:
    543
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    It should work with files. Try this htttp;//xyz.tld/path/xy.html and you should get it redirected to htttp;//xyz.tld/xy.html.
     
    abdussamad, Apr 5, 2007 IP
  6. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    @rodney88
    I had tried that, but its does nothing for me. It only works when I also add rewriteCond %{HTTP_HOST} !^www\.domain\.com to make sure the www is automaticly added.

    @abdussamad
    The problem is that I do not want to copy all the files from the old folder to the main root folder. This is because the CMS only recodnizez the files when they are in the site/blog folder.
     
    Johnburk, Apr 5, 2007 IP
  7. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Eh? By the very definition of a condition, it's impossible to force a rewriterule to apply by adding a rewritecond.

    Do you mean you already have other rewrites in place? If so, it would be helpful if you posted the rest of the codes.
     
    rodney88, Apr 5, 2007 IP
  8. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is how my current .htaccess looks like

    
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    # Redirect to WWW
    rewriteCond %{HTTP_HOST} !^www\.domain\.com
    rewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
    
    Code (markup):
     
    Johnburk, Apr 5, 2007 IP
  9. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #9
    And where is that file? I assume in the root of your domain so that you redirect everything to www?

    You have two choices - if you want to put it in the root, you need to set the paths to only redirect the correct folder:
    RewriteRule ^site/blog/(.*)$ http://www.domain.com/$1 [R=301,L]
    Code (markup):
    If you put an .htaccess in the /site/blog/ folder itself, use the code previously posted.
     
    rodney88, Apr 6, 2007 IP
  10. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The .htacess file is in the root. When I try the above code, I get a 404 error.

    Do I need to copy all the files from the site/blog folder to the root folder? If so, is it possible to have a moderewrite without copying the files? Otherwise the CMS gets messed up.
     
    Johnburk, Apr 6, 2007 IP
  11. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #11
    All this does is (as asked for in OP) redirect www.domain.com/site/blog/* to www.domain.com/*.

    If you haven't actually moved the files, yes you will need to do an internal rewrite back the other way. (Although if you haven't moved it, the whole exercise seems a little pointless)

    domain.com/.htaccess
    # Setup rewriting
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    
    # Redirect old /site/blog requests
    RewriteRule ^site/blog/(.*)$ http://www.domain.com/$1 [R=301,L]
    
    # Force WWW
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
    
    # Rewrite / back to /site/blog
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ site/blog/$1 [L]
    Code (markup):
     
    rodney88, Apr 6, 2007 IP
    Johnburk likes this.
  12. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #12
    rodney, thank you.

    Why is it pointless?
     
    Johnburk, Apr 6, 2007 IP
  13. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #13
    If you're already indexed, there's not much to be gained by moving it all around. You're sending a 301 redirect that takes a valid request and sends it to the root of the domain, only to have to rewrite everything back to its original location anyway.
     
    rodney88, Apr 6, 2007 IP
  14. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Thank you for explaining and your help.
     
    Johnburk, Apr 6, 2007 IP