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 to handle dynamic product url that changes regularly
Hey Moz, It's actually my first post - although I look at the Q&As on a daily basis! I was hoping to get your opinions on how to handle dynamic product url that can change regularly. Before we start, our product page urls get populated by the product titles. So the situation is this. Let’s say we have a product url: /product/12345-abcde-fghj/ Then the client decides to change the title a week later, so the url changes with it to): /listing/12345-klm-qjk Another week later, the agent changes to: /listing/12345-jkhfk-jhf-kjdhfkjdhf So to note, the product ID will always remain the same. Naturally, 301 redirecting every time would cause a bit of page authority to be lost every time 301ed. Also potentially creating new a few hundreds of 301 redirect daily sounds totally mental. (I have been informed by the dev we expect a few hundreds to change url daily) Although I understand there’s no limit on how many 301s you can have on a single domain, this would look completely unnatural - really not ideal. So the potential solution we thought was: we’ll keep the original url, and make sure that is the only url that will get indexed**/product/12345-abcde-fghj/**and put canonical tag on any of the new urls, directing to the original url. The problem we will have then is that the most current url may not exactly match the description of the product -wouldn’t be ideal for ux. Has anyone had dealing with issues like this in the past? Would love to get your input! Many Thanks
Technical SEO | | MH-UK0 -
Changing URLs for SEO
Hi, Currently we have a page, /business, but we have shifted our strategy to optimize for this page for the keyword "enterprise" instead of "business". The page authority of this page is 18 and our domain authority is 35. I've already updated content and title tags to more of an enterprise focus. Would it be wise to move the page to /enterprise and create a 301 redirect from /business to /enterprise? Or is this too risky from an SEO standpoint? Thanks!
Technical SEO | | mikekeeper0 -
Google still listing pages from old domain after 2 change requests
Good Morning I put forward the following question in December 2014 https://moz.com/community/q/google-still-listing-old-domain as pages from our old domain www.fhr-net.co.uk were still indexed in Google. We have submitted two change request in WMT, the most recent was over 6 months ago yet the old pages are still being indexed and we can't see why that would be Any advice would be appreciated
Technical SEO | | Ham19790 -
Suspicious sign in prevented from my php client
I'm using php to try access Google web master tools but its now emailing me about a Suspicious sign in prevented. How can I get round this in a way that it wont effect the security of my account? $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/ServiceLogin");
Technical SEO | | NoisyLittleMonkey
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $data = array('accountType' => 'GOOGLE',
'Email' => 'xxx@gmail.com',
'Passwd' => '***',
'source'=>'PHI-cUrl-Example',
'service'=>'lh2'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $hasil = curl_exec($ch); echo $hasil; ?0 -
Changing title tag in wordpress media pages
Hello! I have a problem of duplicate title on 59 pages in Worpress. I Guess it happened after a recent WP update, because, suddenly, I got a peak of 59 from zero in a day. The SeoMoz crawl report states that there are 59 duplicate title. As you may see in the picture those are all media pages, whose title is written really badly with the formula postname/filename/blogTitle, ending up with trunkated, too long, title tags, that result in duplicate page title. How can I simply hide these mediapages or sculpting the title tag the way I want? I am using all-in-one-seo WP plugin, which doesn't seem to provide a solution. Thank you all! DoMiSol Rossini SOwZg5C.jpg
Technical SEO | | DoMiSoL0 -
/index.php/ page
I was wondering if my system creates this page www my domain com/index.php/ is it better to block with robot.txt or just canonize?
Technical SEO | | ciznerguy0 -
Half Implemented HTML 5 Structure
Hi there, I have just notced on a website that it has a halt implemented html 5 structure. Well, when I say half implemented, it has the doctype and then one <header>section. After that all of the divs are custom ones that have been added for the CSS. Could this lack of structure have a negative effect on the site? Cheers, Edward </header>
Technical SEO | | edwardlewis0 -
On Page 301 redirect for html pages
For php pages youve got Header( "HTTP/1.1 301 Moved Permanently" );
Technical SEO | | shupester
Header( "Location: http://www.example.com" );
?> Is there anything for html pages? Other then Or is placing this code redirect 301 /old/old.htm http://www.you.com/new.php in the .htaccess the only way to properly 301 redirect html pages? Thanks!0