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
-
SERP result (URL) doesn't change after a 301
A couple of months ago there was a result in Google for our branded search term which wasn't the 'official' URL, actually the result shown in the SERP was www.mycompany-ip.nl. We've applied a 301 redirect of this URL to the 'official' URL which is a subdomain: department.mycompany.nl. From Google the redirect is obviously working, but up until now, I don't see Google replacing the incorrect URL by the correct URL. I am wondering what to do to make the result correct. André
Technical SEO | | ConclusionDigital0 -
How to change the woocommerce product page permalink
Sorry Posting it again. How I can change the product URL structure. Please let me know how to fix woocommerce permalink in wordpress. My current URL is http://www.ayurjeewan.com/product/divya-ashmarihar-kwath and I want to like (only post name) http://www.ayurjeewan.com/divya-ashmarihar-kwath Attached is the screenshot of option available. qa2hZMP.jpg
Technical SEO | | JordanBrown0 -
Changing the order of items on page against Google Terms & Conditions?
Good day, I am wondering if anybody here has done something like this before. I have a page in one of my sites that contains a number of different - but related - free resources. The resources can be sorted in different ways once the user is on the page. Now I am starting an outreach campaign, and want to be able to send out custom URLS (which pretty much means they have different query strings after them like '?id=123' ) so that when a person clicks on the link to the page it brings up the stuff they are more likely to be interested in at the top. I expect - hope - that some of these people will put links back to this page as a result of this. Now all the links may be slightly different, but they will come to the same page and the content will look slightly different. I will make sure to have the rel=canonical tag in place. Does anybody know if this would be in violation of Google Terms and Conditions. I can't see how, but I wanted to see what the experts here on Moz think before moving forward. Thanks in advance.
Technical SEO | | rayvensoft0 -
How can I change the page title "two" (artigos/page/2.html) in each category ?
I have some categories and photo galleries that have more than one page (i.e.: http://www.buffetdomicilio.com/category/artigos and http://www.buffetdomicilio.com/category/artigos/page/2). I think that I must change the tittle and description, but I don't how. I would like to know how can I change the title of each of them without stay with duplicate title and description. Thank you! ahcAORR.jpg
Technical SEO | | otimizador20130 -
Is it possible to change a sitelink title by off page SEO?
Hi all, I checked a website of my company: sitelinks in SERP are with the correct url, but one of the sitelinks’ title is completely irrelevant. Is it possible that it was changed from "outside"? Or maybe it's a bug? Thank you, Imre
Technical SEO | | DDL0 -
Could a URL change path conflict a 301 redirect?
Hi Mozzers, We create multiple pages for one of my client. Some of them are replacing old pages. I setup 5 of them out of 40. I was able to set them live via the drupal CMS. The new pages were actually published but didn't have any URL but had nodes in directory such as www.example.com/node298. To set them live i changed the url path to one page that already existed( www.example.com/old). In order to setup the replacing page: www.example.com/node298 i added the same name as the old one but in order to avoid URL conflicts with new page(www.example.com/new) I had to change the old page's url path as well such as www.example.com/old2) I know i have to 301 redirect the old to the new obviously but my question is: does a URL path change on the old page www.example.com/old matters in when 301 ing it? will it still transfer all the juice to the new page Visual Process: Main goal: www.example.com/old redirect to www.example.com/new but these two are exactly the same url So modification of URL path: www.example.com/old to www.example.com/old2 to avoid URL conflict Therefore www.example.com/old2 =www.example.com/old (just url change path difference) Question: Because of this url change, will a 301 from www.example.com/old2 to www.example.com/new will still carry all the juice that www.example.com/old carried or not? I hope i didn't make it too confusing. Let me know if it is the case Thanks Mozzers Ty
Technical SEO | | Ideas-Money-Art0 -
Changing DNS -- SEO implications?
Hey Moz, We're migrating an old site on an old server over to a new server/DNS. The plan is to keep the same URL structure and reuse our existing URL's. As long as we make minimal changes to each page's content, we should be able to update our DNS entry and get all the pages recreated and assigned to their correct URLs without any reduction in SEO rankings. Is this correct? This site gets a lot of organic traffic and ranks highly on some challenging keywords, so it's key that we retain our rankings as much as possible. I've read that it's wise to lower the DNS time-to-live to one hour, about a day before the move, to help Google crawl the DNS a little quicker. Are there any other recommendations you guys can offer or past experiences?
Technical SEO | | stephen_reply0 -
How will a domain change affect my rankings?
My company will undergo a domain change in the next few months. Other than implementing 301 redirects, what else can I do to help the search engines realize the site has moved? What kind of impact on rankings can I expect to see? Thanks in advance!
Technical SEO | | raylau0