Skip navigation
Currently Being Moderated

Setting up Permanent Redirects (and .html go to .php)

May 3, 2012 5:48 PM

Hi all,

 

There is a bigger story but I'll try to keep to just the main issue... I'm a newbie at this so please forgive terms etc.

 

 

GOAL: Setting up permanent redirects from oldsite.com (all html) to newsite.com  (all with the same urls file name but all now = .php)

 

So I want to do 2 things:

 

1 - redirect everything from old site to new site

2 - redirect ALL OLD .htm and .html to NEW .php like:

 

EX: oldsite.com/folder1/test1.html to  newsite.com/folder1/test1.php

 

so in oldsite.com in .htaccess file I added:

 

1 -  at bottom...

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

 

THAT SEEMS TO WORK

 

2 - below or above previous both did not work...

RewriteEngine On

RewriteRule ^(.*)\.html$ $1.php [L]

 

THAT SEEMS TO NOT WORK - it goes to new site but stays on the .html page not the .php version of the same page

 

Q: How do I get this working?

 
Replies
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    May 3, 2012 11:18 PM   in reply to revdave

    You should ideally redirect wildcard from the old domain to the new domain. You need not modify .htaccess. You could use your cPanel to do this for you. Login to cPanel > Redirects. Configure your new domain as a wildcard redirect with 301 Permanent here.

     

    Renaming files from .html to .php happens on your new domain. Open the root .htaccess on your new domain and paste the following code all the way at the top:

     

    Options +Indexes

    Options +FollowSymlinks

    RewriteEngine on

    RewriteBase /

    RewriteRule ^([^.]+)\.php$ $1.html [L]

    Try it out and let us know how it works.

     

    A quick tip: People usually rewrite .php to .html for SEO (even though it doesn't really matter)! But, this is the 1st time I'm seeing a request for rewriting .html to .php! Is there a specific reason why you're moving to .php? Do you have a lot of .php code on your new site?

     
    |
    Mark as:
  • Currently Being Moderated
    May 4, 2012 12:55 AM   in reply to revdave

    You can do this in the htaccess file like below listing all the sites pages BUT it's a bit long winded if you have 30 plus page. There is  much shorter method than listing all the pages which I can't remember but maybe someone else can.

     

     

    redirect 301 /pages/about_us.html http://www.yourDomainName.com/pages/about_us.php

     

    redirect 301 /pages/latest_news.html http://www.yourDomainName.com/pages/latest_news.php

     
    |
    Mark as:
  • Currently Being Moderated
    May 14, 2012 11:37 PM   in reply to revdave

    revdave wrote:

     

    So I'm just double checking that this method listing each page individually on  .htaccess file should be the best way to move from .htm or .html TO .php &  *PRESERVE GOOGLE RANKINGS* - CORRECT?

     

     

    redirect 301 /mypage1.html http://www.samesite.com/mypage1.php

    redirect 301 /mypage2.htm http://www.samesite.com/mypage2.php

    etc.

     

     

    I'm not sure its the most efficient way but its the way I have done it in the past to preserve Google rankings.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points