This article was published more than a year ago, there may have been developments.
Please take this into account.

In today's driving back to talk about “.htaccess“, this time we will use the “mod_rewrite” to change the extension to files so that by making a request to “file.html” the request is turned to “file.php” without altering the URL.

Today's tutorial is very short and very easy. The following lines of code do all the work:

Options  FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

Save the file called “.htaccess“, within the directory where extensions have to be rewritten try to call a PHP file giving it as HTML extension.

If everything works there should be no differences between the file PHP and the file HTML. In reality it is a single PHP file “masked” da HTML. Now all files with PHP extension in the directory where the file resides “.htaccess” They will be displayed even if invoked with the HTML extension.

To get an idea of ​​the functioning this is the PHP page original, inserting the two terms in the box will be called a second file called “result.html“. On the server, instead, the file is loaded “result.php” showing all those words on the previous page. It, this procedure also works with scripts. The URL the user will continue to see “result.html“.

This technique is very useful for example in the case where the internal links of the site we are working on were pointing to an HTML page, which was originally static, but now we want to make it dynamic. Change the links of all the pages would be a huge waste of time, in this way it will be enough to load a single file “.htaccess” with these instructions and the PHP page will be invoked with all of its features even though the extension will continue to be displayed HTML.

  User management in Linux


I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.


TheJoe · 23 October 2011 at 10:05 AM

The stop as I was wrong. The forum of George Tave is clearly more suitable to your question.
But I must point out again that if you decide to overshadow the old pages and just keep the new ones might have an impact on search engines, on the contrary if I left the old pages visited you should have no problems. All this “I think”, I might be wrong.

framework · 22 October 2011 at 8:58 PM

the sitemap and file robort.txt invaritati you leave or you have to make the change extension?

TheJoe · 22 October 2011 at 8:21 PM

Certainly remains unchanged for all search engines, pages “html” are not obscured, as I have already said if you do not set a specific rule further nell'htaccess the same content will be accessible by one or the other extension (html o php).
If you do not seem logical're free to argue, but at least use some argument as I did, not “Remains to Be Seen”.

framework · 22 October 2011 at 7:42 PM

bhe, certainly change there rinominado pages. php. He's using that code to see if you will make sure that everything remains unchanged for search engines. Thank you for having responded cm ²

TheJoe · 22 October 2011 at 5:33 PM

I'm not really an expert in SEO (;)) but as I see it you should not be penalized, at the end of the search engine does not change anything, the old pagie (unless you do not write other rules) remain accessible to him. But I could be wrong.

framework · 22 October 2011 at 4:55 PM

I'll explain; rinonimo pages. html to php and insert the code in the. htaccess not to allow the pages continue to be seen and indexed. html

framework · 22 October 2011 at 4:24 PM

Great guide but I have a doubt. If I rename the pages already indexed. Html to php and insert the code in the. Htaccess what happens in the search engines? I lose positions? pagerank?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.