Shared Know How

Howto: fix, find, use, make & do it guide

handy .htaccess settings I use in a row

author Posted by: Tim on date Apr 16th, 2008 | filed Filed under: linux

I always keep on reinventing the wheel when it comes to .htaccess settings like for automatic redirect to https://, utf-8 character settings or custom error documents. Here are some settings I use.

Automatic redirect to ssl host https:

In case you want to automatically redirect to https to make sure people use the secure connection put the following code in your .htaccess.

Always make sure to use %{HTTPS} off as condition and not any port number.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Custom "page not found" or other error pages

ErrorDocument 404 http://errorurl/
//or the following
ErrorDocument 404 /edocs/404.htm

Make sure host uses UTF-8

if you create websites for others and use a lot of different hosting providers you may notice not everyone uses utf-8. This might create some difficulties with certain characters. Adding the following line to your .htaccess makes sure your host uses utf-8.

AddDefaultCharset utf-8

Code I always put on top to prevent problems with some hosts

-Indexes makes sure your folders aren't indexable from the web. This might prevent some unwanted peeking around on your server colocation.

Options -Indexes +SymLinksIfOwnerMatch

Did this help you? Wanna help too?

tagOne Response to “handy .htaccess settings I use in a row”

  1. Thijs Said,

    To redirect users entering the site at to you can use the following .htaccess rewrite rules:

    RewriteCond %{HTTP_HOST} ^domainname\.com$ [NC]
    RewriteRule ^(.*)$$1 [L,R=301]

     Add A Comment

trackback Trackback URI | rsscomment Comments RSS