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
-
Domain prefix changed, will this impact SEO?
Our web development team have changed our domain prefix from www to non www due to a server change. Our SSL certificate would not be recognised under www and would produce a substantial error message when visiting the secure parts of our website. To prevent issues with old links they have added a permanent 301 redirect from www. to non www. urls until our sitemap catches up. Would this impact our SEO efforts or would it have no impact as a redirect has been placed? Thanks
Technical SEO | | Jseddon920 -
How a change in IP address affects SEO?
Our domain is pretty mature, has several quality backlinks - ranks well for our key terms - but we need to change our IP address because we use a cloud provider and it's a shared IP that has had a security breach. How will this affect rankings? www.layer7.com
Technical SEO | | Layer7Tech0 -
Duplicate Page Title Error passing a php variable
Hi i've searched about this and read about this and i can't get my head around it and could really do with some help. I have a lot of contact buttons which all lead to the same enquiry form and dependant on where it has come from it fills in the enquiry field on the contact form. For example if you are on the airport transfer page it will carry the value so its prefilled in (.php?prt=Airport Transfers). The problem is it's coming up as a duplicate page however its just the 1. I have this problem with quite a few sites and really need to combat this issue. Any help would be very much appreciated. airport-transfers.php
Technical SEO | | i7Creative0 -
Canonicalization of index.html - please help
I've read up on the subject but am new at this so I thought I would just put forth a simple question. We want our home page to be referred to as www.domain.com. We want the search engines to find and return this URl in search results. But the page has to have a name and the actual name is NOT to www.domain.com/index.html. This, I believe is what can cause duplicate cotnent issues (not really duplicate but perceived by the serach engines as duplicate content). Is it best to insert http://www.domain.com/" /> in the HEAD section of the index.html page or am I totally misunderstanding this concept?
Technical SEO | | TBKO0 -
What if meta description tag comes before meta title tag? Do the search engines disregard or penalize if the order is not title then description in the HTML?
Do the search engines disregard or penalize if the order is not title then description in the HTML? A client's webmaster is a newbie to SEO and did just this. Suggestions?
Technical SEO | | alankoen1230 -
Changing our homepage - what to bear in mind?
We're going to refresh our homepage by putting more content on it and a slightly different design. Given that it's our highest authority page, I don't want to screw it up. We're going to keep the titles / meta / copy the same during the transition, is there anything else I should bear in mind to avoid it plummeting down the rankings? I ask as we have a 2nd smaller site and when I changed 1 word in the title of the homepage it lost 40 places on half its keywords. Lesson learned... Thanks in advance for any tips Dan
Technical SEO | | danfk0 -
SEO Benefit/Liability of changing URLs of a 2 year old site
I sell RV Parts online. Our organization is called The ROUTE 66 RV Network, so we brand everything around ROUTE 66. When we launched our store 2 years ago, we launched it with the domain: parts66.com We have a PR of 2, and we have been doing an SEO linkbuilding campaign ever since it has been around. Our primary keyword that we are trying to rank for is RV PARTS We also own the domain: rvparts66.com My question is: Is there a significant benefit to switching our URL to RVPARTS66.COM? Does having our primary keyword a part of our URL give us an SEO benefit? If so, what is the best way to keep any credit we have built for our original domain? We are in the process of a complete site overhaul which will launch in a couple weeks, so if there is ever a time to switch domains, the time is now. Thanks! jc
Technical SEO | | steve-2886180 -
Is there any value to a home page URL adding the /index.html ?
For proper SEO, which version would you prefer? A. www.abccompany.com B. www.abccompany.com/index.html Is there any value or difference with either home page URL??
Technical SEO | | theideapeople0