Common .htaccess settings to optimize your website

These are snippets for your .htaccess file, comments are after the # hash tags and explain what each snippet does.

Replace “yoursite.com” with your actual website, of course!


# www on all URLs.
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/\ [L,R=301]
 
# Switch to HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
# Ensure all web addresses have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.yoursite.com/\/ [L,R=301]

The “L” in the square brackets tells the server if your rule is fulfilled with a match that is the “Last” directive to follow. The “R” stands for “Redirect” and allows you the option of defining what kind of redirect, typically, this is a 301 Permanent Move.

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *