Php to html - change in extension
-
Hello, What is the code to redirect all the pages of a site from .php to .html extension? Thanks
-
I agree with you not to use any extension and will be looking for a code for this purpose.
-
Hello Zachary,
Where should i enter the line mentioned by you ? After the code provided by Daniel ?
Will it redirect all the external links ?
-
Thanks a lot daniel for your advice.
-
I'd suggest that if you can to not use any extension in the displayed URLs. That way the next time you change languages the URL won't change. As an example, see the SEOmoz URLs -- it's just http://www.seomoz.org/q/php-to-html-change-in-extension with no extension.
I don't know the code offhand for that, but I'm sure others can help you out with that.
-
Atul,
You definitely don't need to contact webmasters to change any links.
There is a 301 redirect flag you can apply to your rewrite rule:
RewriteRule ^(.*).html$ $1.php [R=301,L]
Do a 301 redirect test to confirm. Best of luck!
-
1. Yes since the code I gave you will rewrite the extension of every single page FROM php to html. From html to php would mean the same thing, since a link pointing to products.php would no longer work. The rewrite only rewrites the extensions and not the links.
2. Yes contacting the webmasters and changing the links would be better than doing 301 redirects of all your pages.
I advise to test this on a testing server first, especially if your site has a lot of pages.
-
Thanks Daniel.
"Remember you'll need to make sure to change all the links on your site, and all external links too."
1. Do you mean i will have to manually change all the internal links on the site ?
Shall i have to do this in the reverse case too ? For example changing html to php ?
2. For external links, should i contact the webmasters of the site linking to me ?
-
Add into your htaccess file :
RewriteEngine on
RewriteBase /
RewriteRule ^(.*).html$ $1.php [L]Remember you'll need to make sure to change all the links on your site, and all external links too.
The only other way around changing all the links would be to do 301 redirects for each URL which is, in my opinion not really worth all the work involved since .php and .html should both rank equally in Google and other search engines.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
How Often Can I Change My Meta Titles? (Product Discounts)
Hello, I have an ecommerce website. Due to discounts and sales on most of my products, the discount rates change very often. Some products have %10 discounts for 3 days and then same products might have %50 discounts for another 5 days. I would like to show these product specific discounts on Meta Titles and Descriptions dynamically. My system will automatically update the Meta Titles once the discount on a product changes. My question is, how often can I change the Meta Titles? Is changing them (only discount rates = 1word) too often bad for my SEO? What is Goolge's approach on this? Thank you in advance for all your help. Best,
Technical SEO | | yigitgok
Yigit0 -
Site address change: new site isn't showing up in Google, old site is gone.
We just transitioned mccacompanies.com to confluentstrategies.com. The problem is that when I search for the old name, the old website doesn't come up anymore to redirect people to the new site. On the local card, Google has even taken off the website altogether. (I'm currently still trying to gain access to manage the business listing) When I search for confluent strategies, the website doesn't come up at all. But if I use the site: operator, it is in the index. Basically, my client has effectively disappeared off the face of the Google. (In doing other name changes, this has never happened to me before) What can I do?
Technical SEO | | MichaelGregory0 -
Changes to 'links to your site' in WebMaster Tools?
We're writing more out of curiosity... Clicking on "Download latest links" within 'Links to your site' in Google's WebMaster Tools would usually bring back links discovered recently. However, the last few times (for numerous accounts) it has brought back a lot of legacy links - some from 2011 - and includes nothing recent. We would usually expect to see a dozen at least each month. ...Has anyone else noticed this? Or, do you have any advice? Thanks in advance, Ant!
Technical SEO | | AbsoluteDesign0 -
Https - should I do change of address on WMT
We have added a SSL cert to our site - Should I submit change of address on WMT and submit a new sitemap from the http?
Technical SEO | | webguru20140 -
Web address change - Search impact?
Hi, I have whosjack.org and wjlondon.com - on there is a London relevant news and events website. whosjack.org has been the main site for some time and has decent search pick up. Currently wjlondon.com just redirects to whosjack.org. However - having london in our actual address would be far more beneficial for us. So ideally I want to swap the two web addresses around. Have the main site at wjlondon and have whosjack redirecting to it. However - I don't want to loose traffic from search. An idea I had was to create a sept site at wjLondon that was a feed of social content and links from whosjack so that it starts to get a decent search and then swap them over but not sure whether that would actually be detrimental what with all the dupe content issues with google etc. Any thoughts?
Technical SEO | | luwhosjack0 -
IP address changed and some rankings drop
I changed my hosting company coz better server hardware and results (google). My website was perfectly for every queries on google but after changing company and ip address some results dropped to second page. What can i do now? These drops caused by changing ip address?
Technical SEO | | umutege0 -
Can anyone recommend an SEO friendly Joomla extension to use for SEO on an existing website?
Can anyone recommend an SEO friendly Joomla extension to use for SEO on an existing website? I have downloaded sh404sef but I don't want to change my URL's and make them longer than they are at the moment. Any ideas?
Technical SEO | | Karen_Dauncey0 -
How much of a hit to changing urls?
Hi, We have a few pages that from an SEO perspective have poor URLs. We are planning on changing them (and 301 redirecting) the old page to the new page. I heard in the past, this can temporarily negatively impact your SERP rank etc. Since the old URLs are bad, even if there is a temporary negative hit, changing them in the long run it is better, but curious if anyone has any experience on what to expect.
Technical SEO | | NicB10