Yireo tutorials

Learn more about Joomla!TM and Magento
You are here: Home Tutorials Joomla! Joomla administration Redirect html-suffix in your URLs

Redirect html-suffix in your URLs

Within the Global Configuration of Joomla!TM there is an option Add suffix to URLs that allows you to add the extension ".html" to every URL generated by Joomla!. But if you switch on or off this settings, all your old URLs will become invalid. This tutorial shows you how you can add a new RewriteRule to the Apache htaccess-file to redirect all old URLs to their new version.

Finding the option in the Global Configuration

joomla_global_seoThe option Add suffix to URLs should be easy to find. It's located in the Global Configuration within the Joomla! backend. Under the tab Site you will find some SEO-settings on the right. The option Add suffix to URLs adds the suffix ".html" to your URLs, but this requires the option Search Engine Friendly URLs to be turned on. We also recommend to turn on the option Use Apache mod_rewrite but this requires the usage of the Apache webserver and the existence of the file .htaccess.

Switching off the suffix

If you disable the suffix, you will want all your old URLs with the ".html" suffix to redirect back to their equivalent without the suffix. To accomplish this the following rules just after the statement "RewriteEngine On":

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ /$1 [R,L]

This will make sure only dynamic SEF URLs ending with ".html" will be redirected. If you have a static HTML-page this will not be redirected.

Switching on the suffix

If you were previously using URLs without a suffix and want to switch to URLs ending with ".html" you will need to accomplish the opposite.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^(.*)$ /$1.html [R,L]

The code is slightly different from the code above. Again, this is only applied to dynamic Joomla! files, not static HTML-files.

More tricks

The Joomla! Documentation project has already listed other tricks that can be applied through changes in your htaccess-file. If you go to docs.joomla.org and search for "htaccess" you will get a nice listing.

 

Payments Methods

Payment Methods