Apache mod rewrite in Joomla

From Proxmox VE
Jump to: navigation, search


The standard Joomla Template does not have the enabling code for Apache mod-rewrite to work. While SEO optimisation can be turned on inside Joomla rendering URLs containing index.php, it is Apache mod-rewrite that makes the URLs fully Search Engine Friendly (SEF) without (the index.php in the URL) it.

The following instructions will enable one to use the Apache mod-rewrite in Joomla containers based on the standard template.

Apache Conf

Edit the file /etc/apache2/sites-available/joomla replacing the following:

<Directory /var/www/joomla>
        Options FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

with the following:

<Directory /var/www/joomla>
        Options All
        AllowOverride All
        Order allow,deny
        allow from all


On the console execute the following:

mv /var/www/joomla/htaccess.txt /var/www/joomla/.htaccess
a2dissite joomla
a2ensite joomla
/etc/init.d/apache2 reload

htaccess contents

The working contents of the htaccess.txt file taken from Joomla v1.5.22 (same in v1.6.0 as well) is listed below:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

In some instance the first line in the above may be commented out (prefixing with #) if errors occur.


Login to the administrator Web GUI at http://IP.or.Domain/administrator as the Super Admin (admin) and choose to enable SEF and mod-rewrite in the Global Configuration and save.


Check out the site and navigate to the various pages to see that the URLs now do not contain any index.php / file names / file extensions at all.