Rewrite rules - redirect from old URL to new URL

Discussion in 'Apache' started by ovisopa, Sep 20, 2005.

  1. #1
    Hello,

    today I made some changes to my site, there are ~1000 links which are changed from photo_galery.php?album=3 ... and photo_pop.php?photo=980 to /photo-gallery/my-album-name/3/ and /foto/photo-name/980/

    What is the better way to make google spider my new files and forget about the old files ?

    Should I ad in the old files the field <META name="Robots" content="noindex,follow">

    Should I make an redirect header("Location:/new-path-to-files/"); ? ( do I need to add another header before Location:... ? )

    Which is the best way ? or other better alternatives ?

    10x in advance ;)

    Bye
     
    ovisopa, Sep 20, 2005 IP
  2. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
    #2
    If you are on an Apache server, insert a 301 permanent redirect statement into the .htacess file. See the DigitalPoint Apache forum for instructions on how to do this. Note that most people will tell you you need to use mod_rewrite to do this, which is incorrect. It may be the most efficient since you can use wildcards but you may not be able to use mod_rewrite on some server configurations. If so, you can use the following:

    Redirect 301 /oldpage.html http://www.domainname.com/newpage.html 
    Code (markup):
    for each page that has changed.

    If you cannot use .htaccess, there are other ways to do a permanent redirect. For example you can use PHP or ASP if your server supports either of those:

    For PHP:
    <?PHP 
    header("HTTP/1.1 301 Moved Permanently"); 
    header ('Location: http://www.newsite.com/newpage.html'); 
    exit (); ?> 
    Code (markup):
    For ASP:
    <%
    response.Status = "301 Moved Permanently"
    response.addheader "location", "http://www.newdomain.com/page.html"
    response.end
    %> 
    Code (markup):
    Or you can use the meta-refresh:

    <HTML>
    <HEAD>
    <META HTTP-EQUIV="REFRESH" 
    CONTENT="10; URL=http://www.yourdomain.com/newpage.html"></head>
    Code (markup):
     
    minstrel, Sep 20, 2005 IP
  3. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    From the format of your new URLs it looks like you're using mod_rewrite already. If that's the case, you may be able to redirect the current URLs by adding an [L] flag to your existing RewriteRules to tell the server that this the last rule which should be obeyed and it should stop rewriting now, and then add in some RewriteCond / RewriteRule pairs to handle changing the old style urls to the new style.
     
    johnt, Sep 20, 2005 IP
  4. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
    #4
    [quote-johnt]From the format of your new URLs it looks like you're using mod_rewrite already.[/quote]
    Doh! :eek:

    I think it's probably safe to say that... need more coffee :eek:

    But still, the post does point out that there is more than one way to skin that cat too
     
    minstrel, Sep 20, 2005 IP
  5. ovisopa

    ovisopa Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    10x for your alternatives :)

    I think I will use
    <?PHP
    header("HTTP/1.1 301 Moved Permanently");
    header ('Location: http://www.newsite.com/newpage.html');
    exit (); ?>

    in my case this is the easiest and fastest way to do it .. and if it's ok for google I'm Happy with it. I just need to edit 2 files . that's all . :)
     
    ovisopa, Sep 20, 2005 IP
  6. ska_kashif

    ska_kashif Active Member

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #6
    only put this code in .htaccess file

    redirect 301 http://abc.com http://xyz.com

    http://abc.com is old url
    http://xyz.com is new url

    so, old url will be change into new rul of a site.
    if i want to change all pages of http://xyz.com
    then what have to do?

    kindly explain that how to put which one code in .htaccess file
     
    ska_kashif, Jun 18, 2010 IP