Problem with my 301 redirect

Discussion in 'Apache' started by Sxperm, Feb 24, 2007.

  1. #1
    Hi,

    I just did 301 redirect for entire new domain to the old one using this in .htaccess

    redirect 301 / http://www.domain.com/

    I place this code in the first line and it should redirect all pages under this site to the new one, but my problem is, Google cached some page on my new site already and it cause me a problem. It has been redirected to the wrong way like this. When I entered google cached page

    http://www.domain.net/(folder name)/(filename).html

    it has been redirected to

    http://www.domain.com(folder name)/(filename).html

    it just changed url but not put trailing slash at the last char. Actually, I want all pages under this new site redirected to my new http://www.domain.com only, not even redirected to subpage because my new site has different path from the old one. How do I fix this problem. I don't want google to cache 404 error page on my new site.
     
    Sxperm, Feb 24, 2007 IP
  2. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This problem should only occur if you miss the trailing slash in Redirect url like this:

    Redirect 301 / http://www.domain.com

    Have you tried by typing it in your browser instead of going through google cached page?

    You can use mod_rewrite instead:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule / http://www.domain.com/? [R=301]
    </IfModule>

    The trailing '?' in RewriteRule with strip all of the path information and query strings as you desired. But its a good idea to rewrite rule the old pages to the new location if possible instead of redirecting to the domain home page.
     
    Cybernaut, Feb 25, 2007 IP
  3. ma0

    ma0 Peon

    Messages:
    218
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have a similar problem..

    I have a site www.xxx.com with a redirect 301 to blog.xxx.com
    the problem is that I have www.xxx.com/awstats and I can't see it because the redirect moves me to blog.xxx.com/awstats..
    how does I stop the recursive thing?
     
    ma0, Feb 26, 2007 IP
  4. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you want to redirect all pages to blog.xxx.com except /awstats, use this:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/awstats [NC]
    RewriteRule / http://blog.xxx.com/? [R=301,L]
    </IfModule>

    Use trailing '?' only if you want to strip path information and query string.
     
    Cybernaut, Feb 26, 2007 IP
  5. ma0

    ma0 Peon

    Messages:
    218
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, I'd like to use it only until I have something decent to show on the front page.. I will leave the ? ..I don't really mind if someone write something after the tld. I just want to make the life easier for who remember just the domain and forgot about the "blog." before it.

    Btw. do you know a good cheat sheet for .htaccess? I have read some website yesterday, but I immediately forgot some of the stuff, especially the [] :)
     
    ma0, Feb 26, 2007 IP
  6. ma0

    ma0 Peon

    Messages:
    218
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It appears that it doesn't work. Very strange because I tested it and it worked.. now it doesn't.

    Or maybe I haven't tested it?
    Or maybe DreamHost is again on trouble with apache rules? :(
     
    ma0, Feb 26, 2007 IP
  7. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    LOL, you mean first it worked, then it stopped working. :)

    Better put a php script (index.php) there that should do the redirect then.

    <?php
    
    header('Location: http://blog.xxx.com/');
    
    ?>
    Code (markup):
    or a simple html page (index.html) with a meta refresh or javascript redirect in it.
     
    Cybernaut, Feb 26, 2007 IP
  8. ma0

    ma0 Peon

    Messages:
    218
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well, maybe you are right..
    but I soo want to learn how to use .htaccess files :)

    And maybe it's better to avoid to waste cpu time with php when you can use apache.. :)
    I'd like to be an EcoWebmaster :D :cool:
     
    ma0, Feb 27, 2007 IP