Call Us: 512.271.5221

29
July
2017

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 (click for more variants)

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 (click for more variants)

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]

 


 

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

RewriteEngine On

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

RewriteRule ^index.php/(.*) /$1 [R,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 http://www.mysite.com/content/view/1234/2/ to  http://www.mysite.com/index.php?option=com_content&view=article&id=1234/2

 


 

Move website, remove folder name from path

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

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

RewriteRule ^folder/(.*) http://www.example.com/index.php/$1 [L,R=301]

or shorter version:

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

 


 

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

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

 

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

certified web designer

Get Started with YellowWebMonkey

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator

Joomla Maintenance Plans

Get started with reliable monthly care provided by a Joomla certified company.

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Hire YellowWebMonkey

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator

Learn More

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator

Request More Info

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator

Contact YellowWebMonkey

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator

Sign Up with YellowWebMonkey

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator

Same Day Estimate

Invalid Input

Invalid web address.

Invalid Input

Invalid Input

Joomla Certified Administrator

Prefer to talk on the phone?

Click to call 512-271-5221 or

Invalid Input

Invalid Input

Prefer to talk on the phone?

Click to call 512-271-5221 or

Invalid Input

Invalid Input