dizzysoft

web development for search engine optimization

Basic .htaccess Template- Explained

Every site needs an .htaccess file. Still, with every website I build I always forget what to put. So I thought it would be a good idea to write up one, simple .htaccess file that could serve as a template for my websites- and maybe yours as well:


# do not allow anyone else to read your .htaccess file
<Files .htaccess>
deny from all
</Files>

# forbid viewing of directories
Options All -Indexes

# hide this list of files from being seen when listing a directory
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

# disable the server signature- helps with preformance
ServerSignature Off

# since it's out of fashion to use www- redirect URLs to non-www
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^.*$ http://website.com%{REQUEST_URI} [R=301,L]
RewriteBase /
# keep the URLs clean:
# if someone asks for index.php- rewrite the URL without it
RewriteRule ^(.*?)/?index\.php$ $1 [NC,R=301,L]

Tags:

3 comments about Basic .htaccess Template- Explained

  • Thank s for this wonderful little Gem David.

    I began to programme with Basic and assembly language back in 81/82 with the Z80 and 6502 I think it was but never carried on with programming. Became hardware electronics Tech in the Royal Navy instead (:

    Little bit learnt still comes in handy now and then

    All the best

    Harry

    • There are so many important things your can do with your htaccess file, the basic file here is just to get you started.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Examples

Recent Comments

Topics