Switching site from html to php; broken link redirection?

Discussion in 'PHP' started by IanT, Jul 18, 2010.

  1. #1
    I was thinking of switching one of my sites from html to php, but I have thousands of backlinks for the .html files.... I have heard you can redirect to the new links....


    what is the best way to do that?


    I found this:



    Will that work?

    or do I need to do something different...

    Basically Im going to make a new .php page for every page that is .html and I want the users to be redirected to the new pages so I dont lose any of my backlinks etc...

    Ive been trying to do things and I think keeping it html is going to make me need to use many methods/lines of code instead of using few php scripts..


    pleeeease help!! I want to get this done today!
     
    IanT, Jul 18, 2010 IP
  2. adamsinfo

    adamsinfo Greenhorn

    Messages:
    60
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    I don't think you can use 'Redirect' in the .htaccess to do this, you can try "Redirect *.html *.php" but that probably won't work. You need RewriteRule & RewriteCond
     
    adamsinfo, Jul 18, 2010 IP
  3. savageman123

    savageman123 Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    RewriteEngine on
    RewriteRule ^(.*)\.html $1.php [R=301,NC]
    Code (markup):
    Will do a permanent redirect from page.html to page.php

    Depending on how you plan on switching over, you may want to use a check and only redirect if no html file exists, that way once the file is renamed it will automatically go to the new .php but not before, you would place this above the RewriteRule line.

    RewriteCond %{REQUEST_FILENAME} !-f
    Code (markup):
     
    savageman123, Jul 18, 2010 IP