Redirect html to php where filename is NOT the same

Discussion in 'Apache' started by Jez, Nov 15, 2007.

  1. #1
    Paypal donation of $20 to your favourite charity for the answer that works best!

    I have a problem where I have changed from a script that generated static html pages to one that produces php pages. I want to redirect all the old html pages (around 2500) to the new php pages BUT the filenames are not the same. Is there a way to redirect all the .html pages to www. domain.com or better still, to somehow redirect to the corresponding filename although it's not the same?

    I should mention that the pages (php and HTML) are all in the root folder. I don't know if that makes a difference or not.

    I hope I have included enough details.

    Thanks,

    Jez.
     
    Jez, Nov 15, 2007 IP
  2. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #2
    hi, you can use this:)

    RewriteEngine On
    RewriteBase /

    RewriteRule ^([^/]*)\.html$ /index.php?oldpage=$1 [L]

    in a .htaccess file in your root folder

    in your index.php you can recall the html page entered with:

    $_GET['oldpage']

    for example (index.php)
    <? print $_GET['oldpage']; ?>

    if i enter yoursite.com/cow.html
    it will show cow in the index page
     
    pig2cat, Nov 16, 2007 IP
  3. Jez

    Jez Well-Known Member

    Messages:
    532
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    138
    #3
    Hi pig2cat,

    Thanks for your help. I just tried the .htaccess code and it works. It's a very interesting solution. How will the search engines see it? Will they see it as a 301 redirect or as cloaking? Can it be changed so that the old URL does not show and it just redirects to the index page?

    Thanks.

    Jez.
     
    Jez, Nov 16, 2007 IP
  4. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I believe the search engine's will just see it as cloaked. this is serverside so it's unlikely that the SE's will notice..(i'm not an expert on this so i don't really know tho..)
    To 301 it. you need to change the [L] to [R,L]
     
    pig2cat, Nov 16, 2007 IP
  5. Jez

    Jez Well-Known Member

    Messages:
    532
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    138
    #5
    Hi pig2cat,

    When I change [L] to [R,L] I get domain/index.php?oldpage=index. When I just use [L] I get a clean domain/ URL. Is there a way to have the 301 redirect plus the clean URL?

    Again, thanks for your help!

    Jez.
     
    Jez, Nov 17, 2007 IP
  6. Jez

    Jez Well-Known Member

    Messages:
    532
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    138
    #6
    I had a play about and this is what I used in the end/ currently:

    RewriteEngine On

    rewriteRule ^([^/]*)\.html$ http://www.domain.com/ [R,L]

    Does that look OK to everyone? It just 301 redirects all old html pages to the domain (I hope that's what it's doing - it appears to work).

    Can anyone verify that this will do what I want? Conserve the rankings and PR of the old pages but not get me penalised by google.

    Thanks,

    Jez.
     
    Jez, Nov 17, 2007 IP
  7. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #7
    This just redirects them yes, the solution i gave, sent the name of the origional html page to the index page so you could do php things with it.

    the way you use it now just redirects everything to the homepage, google will know that the pages aren't there anymore... so i doubt they'll keep PR if they don't exist anymore...
     
    pig2cat, Nov 17, 2007 IP
  8. Jez

    Jez Well-Known Member

    Messages:
    532
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    138
    #8
    But the old pages should transfer their PR to the main page now though shouldn't it?

    Thanks for your help. Where do you want the $20 donation to go to?
     
    Jez, Nov 17, 2007 IP
  9. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #9
    hmm, I don't really know any charities that accept paypal. I only donate to funds that come by the doors....
    So you can send it to your favorite charity, or keep it:)
     
    pig2cat, Nov 19, 2007 IP
  10. Jez

    Jez Well-Known Member

    Messages:
    532
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    138
    #10
    I found one that takes paypal. BBC Children in Need.

    Screen Shot below:

    paypal donation.jpg

    Thanks for your help!

    Jez.
     
    Jez, Nov 22, 2007 IP