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?
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?
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
Hi Sudarshan,
Thanks for your help. This did not go from html to php...
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^.]+)\.php$ $1.html [L] - did not work
but this line change did work....
RewriteRule ^([^.]+)\.html$ $1.php [L] - did work
-----------------
However the url at site 2 uses the php page but the url says .html
I want to end up on the real .php page....
so - maybe I do not want any rewrite at all - but just a basic redirect?
MAIN GOAL: to go from old site 1 (html) to site 2 with php equivalents *AND KEEP ALL GOOGLE AND OTHER SEARCH ENGNE RANKINGS!!!!
I'm only guessing at the best proceduce so I'd really appreciate some help
BTW: and yes we did add php functionality to the new site - that's why the change....
I found this...
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
here - http://www.webweaver.nu/html-tips/web-redirection.shtml
and I put it on SITE 1
IT SEEMS LIKE *EXACTLY WHAT I NEED* ....
and it goes from site 1 to site 2 but does not redirect to the pgp page
Am I doing something wrong?
here's what author said...
This example is perfect if you've decided to switch to .php from .html pages. It will look for any .html page and redirect it to .php (ie http://www.example.com/yourpage.html and redirect it to http://www.example.com/yourpage.php). Now, be careful with this, it does mean any html page. I did this on one of my sites and had totally forgotten I had an iframe with .html content on some pages... I didn't notice for weeks that it was broken :S.
So learn from my mistake ;-) check, double check, then check again.
Hi osgood,
your line at site 1 does work just right....
redirect 301 /test1.html http://www.site2.com/test1.php
it would seem to dod the MAIN job of *KEEPING GOOGLE RANKINGS* - CORRECT?
so I wonder if there's a way on site1 to NOT have to list every page and just do some king of master rewrite here like:
take all .html and redirect to SITE2 and ALL .php...........
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.
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.
North America
Europe, Middle East and Africa
Asia Pacific