fbpx
Call us +1-231-421-7160

Common htaccess Rules

The htaccess file is an important configuration file that sits in the root directory of your Joomla Instance. The htaccess file can be used to override certain server configuration settings or provide or block access to the site or directories. It even has useful URL rewriting capabilities. Below you fill find common uses for the htaccess file.

IMPORTANT: Making modifications to the htaccess file can potentially disable or break your Joomla Instance. The CloudAccess.net Support Team does not provide troubleshooting outside of what is listed below.

To www or not www, That is the Question!

Forcing https with SSL

Creating a Vanity URL

Whitelist IP Addresses

Blacklist IP Addresses

301 Redirect all Non-primary URLs to Primary URL (non-https)

301 Redirect all Non-primary URLs to Primary URL (https)

To www or not www, That is the Question!

You may find that your Joomla Instance is indexed by search engines as both www.yourdomain.com and yourdomain.com. It is a good idea to stay consistent with your branding and force all traffic through either one or the other. These rules can be placed anywhere below Mod-Rewrite section of your htaccess file.

Redirect to www
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Redirect to non-www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Forcing https with SSL

When setting up an SSL, you will have the ability to route traffic through a secure port 443. This is usually done by forcing https within the Joomla Global Configuration settings. You can also force all or certain pages to https from within the htaccess file. To do so, place the following code below Mod_Rewrite

RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Creating a Vanity URL

You may find that an architected URL is needed in certain cases. While we recommend using core-Joomla to generate your URLs, it is not always possible to do so appropriately. For example, if you have a promotional offer that requires a shortend URL, you may decide to redirect www.yourdomain.com/promo123 to a specific article. Add this rule after the Mod-Rewrite

RewriteRule ^promo123 /full-path/to-desired/page.html [R=301,L]

Whitelist IP Addresses

In some cases, you may find it beneficial to block your instance from the world and only allow a handful of IP addresses to view either the front end or back end only. To do this, utilize the “allow from” rule. IMPORTANT: blocking access may reduce the ability for CloudAccess.net to support your Joomla Instance. Contact us for a list of support IP addresses. To implement this rule, place it at the very beginning of your htaccess file.

Order Deny,Allow
Deny from all
Allow from 111.22.3.4
Allow from 111.22.3.5

Blacklist IP Addresses

Similar to limiting access by allowing only certain IP addresses, you also have the ability to block access by IP addresses. This is done by using the “deny from” rule, and can be set to block specific IP addresses or entire IP address ranges. To implement this rule, place it at the very beginning of your htaccess file.

Order allow,Deny
Deny from 111.22.3.4
Deny from 111.22.3.
Allow from all

301 Redirect all Non-primary URLs to Primary URL (non-https)

In some cases when using the CloudAccess.net Alias Tool in the CCP, you will find that it is necessary to go a step further to provide proper 301 redirect. Be sure to indicate the specific "casite" number in the 3rd line to ensure your alternate URL continues to work properly. 

RewriteCond %{HTTP_HOST} !^primarydomain.com [NC]
RewriteCond %{REQUEST_URI} !administrator
RewriteCond %{HTTP_HOST} !^casite-#####.cloudaccess.net [NC]
RewriteRule (.*) http://primarydomain.com/$1 [R=301,L]

301 Redirect all Non-primary URLs to Primary URL (https)

RewriteCond %{HTTP_HOST} !^domain\.com [NC]
RewriteRule (.*) https://domain.com/$1 [R=301,L]

Do you have suggestions for improving this article?  

We take a great deal of pride in our knowledgebase and making sure that our content is complete, accurate and useable. If you have a suggestion for improving anything in this content, please let us know by filling out this form. Be sure to include the link to the article that you'd like to see improved. Thank you!