Note: The solution presented in this post involves a modification to a core Joomla file. Please proceed with caution and keep in mind that a core modification can be wiped out with a future Joomla update, potentially breaking your website (or, at best, breaking your website’s links).
Every now and then, a client calls us and tells us that his company wishes to have the suffix of their website’s links to be something other than html. Usually, the client wants to change the suffix from html to either php or htm. Nearly every time we had this call, the client expected to be able to do this by changing a setting in Joomla’s backend. Of course, the first thing that we do is that we tell the client that this is not possible – and that core modifications are required in order to do that. We then get approval from the client to implement the solution for him and we proceed to work!
Now, since we are at itoctopus super-generous with an obsession of knowledge sharing, we are going explain the process of changing the suffix on a Joomla website from html to php in this post. Here’s how:
- Open the file site.php which is located under the libraries/cms/router folder.
-
Find this line (should be line 110 in Joomla 3):
$vars['format'] = $suffix;
Replace it with:
$vars['format'] = 'html';
-
Find this line (should be line 144):
if ($format = $uri->getVar('format', 'html'))
Replace it with:
if ($format = $uri->getVar('format', 'php'))
-
That’s it! That’s really it! There’s nothing more to do!
This seems super easy! Is there a caveat?
Well, actually there is. The problem with the above method is that you will have duplicate links, for example, both http://www.[your-joomla-website].com/page-1.html and http://www.[your-joomla-website].com/page-1.php will work (obviously, Google will not like that). However, the solution to this problem is very straightforward. All you need to do is to add the following line to the beginning of your .htaccess file:
RedirectMatch 301 (.*)\.html$ http://www.[your-joomla-website].com$1.php
The above line will solve the problem.
Will the above method work for a suffix other than “php”?
If you want to change the suffix of the links on your Joomla website from html to anything else, then just replace php in the code above to the suffix of your choice. You need, however, to make sure that you add the following line to your .htaccess file (to tell Apache to process any URL with an unknown suffix as HTML):
DefaultType text/html
If you need help implementing the solution above, then look no further as we are here to help! Just contact us and let us prove to you how efficient, knowledgeable, and affordable we are!