Call Us: 512.271.5221


All the Joomla htaccess redirects you will ever need

Here are the quick code snippets for common tasks you need to do in .htaccess to do redirects for Joomla, or any site for that matter.  Most are linked to its own blog post that explains it in more detail.  


Htaccess redirectsIn all reality, I am sure this post is missing several that would be helpful.  If it isn't listed, please comment on post and let me know which others should be on the list.



HTTP Redirects

Force HTTPS on whole site

RewriteCond %{HTTPS} off

RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


Force HTTP on whole site

RewriteCond %{HTTPS} on

RewriteCond %{REQUEST_URI} !protected [NC]

RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]



WWW Redirects

Force www to non-www

RewriteCond %{HTTP_HOST} !^www\.

RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


Force non-www to www

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]

RewriteRule ^(.*)$ http://%1/$1 [R=301,L]



Joomla 3.8 Experimental URL Routing

Redirect old URLS with id to new ones

RewriteCond %{REQUEST_URI} (.*)\/(\d{1,}-|)(.*)\/(\d{1,}-|)(.*)
RewriteRule ^(.*)(\/)(.*) %1/%3/%5 [L,QSA,R=301]


Click on Joomla 3.8 Experimental URL Routing title link for more info.



Trailing Slash redirects

Remove trailing slash

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} (.+)/$

RewriteRule ^ %1 [R=301,L]


Add trailing slash

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} /(.*)/$

RewriteRule ^ /%1 [R=301,L]



Remove index.php from Joomla SEF Links

Remove from middle of url

RewriteCond %{REQUEST_URI} ^/index\.php/

RewriteRule ^index.php/(.*) /$1 [R=301]


Remove from end of url

RewriteCond %{REQUEST_URI} !^.*/administrator/index\.php [NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?) [NC]

RewriteRule ^ /%1 [R=301,L]


Removing the Temporary Url ~username out of Your Link

1. Comment Out with a #:

RewriteBase /~username/


2. Then add redirect, subbing out with your username:

RewriteEngine On

RedirectMatch 301 ^/~username(.*)$ $1



Redirect IP address to domain

RewriteCond %{HTTP_HOST} ^111\.111\.11\.111$

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]



Change URL from old folder to new folder

RewriteEngine On

RewriteRule ^oldfolder/(.*)$ /newfolder/$1 [R=301,NC]



Redirect Joomla 1.0 SEF links for Joomla 3.x

RewriteBase /

RewriteRule ^content/view/(.*)$ /index.php?option=com_content&view=article&id=$1 [L,R=301] 

That will redirect to



Move website, remove folder name from path

RewriteCond %{THE_REQUEST} ^GET\ /folder/(.*)

RewriteCond %{THE_REQUEST} ^GET\ /folder/(.*)

RewriteRule ^folder/(.*)$1 [L,R=301]

or shorter version:

RewriteRule ^folder/(.*)$ /$1 [L,R=301]



Remove .html from URL

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/

RewriteRule ^(.*)\.html$ /$1 [R=301,L]



Force domain to HTTPS but set subdomain to HTTP



Here are some others I plan to add later when I get time:

  • Remove Query String from link
  • Add folder to link
  • Match folder and remove everything before it
  • Redirect one folder to another folder
  • Redirect subdomain to folder
  • Match query string and redirect to page


Common Problems and Things to Check

If any of these aren't working, please double check that you have the RewriteEngine On and have substituted the appropriate placeholders (, folder, username, etc)


If you are getting 500 server errors, try enabling/disabling the various commands that start with "Options," like Options +Indexes and Options +FollowSymLinks. Their usage varies widely between hosting companies where having it or not having it will throw 500 server errors.


If you are getting double index.phpindex.php then find these lines:

########## Begin - Rewrite rules to block out some common exploits
RewriteCond %{QUERY_STRING} proc/self/environ [OR]

and add in this extra conditional:

########## Begin - Rewrite rules to block out some common exploits
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{QUERY_STRING} proc/self/environ [OR]


Bonus Items

Also, if you need to tinker with the code, this tool by madewithlove is the best thing since sliced bread: .htaccess Tester


A great starting point for comprehensive security tweaks and so forth is the Master Htaccess written by the creator of Akeeba Backup and Admin Tools: Download Master .htaccess

Categories: .htaccess

blog comments powered by Disqus

certified web designer

Get Started with YellowWebMonkey

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator