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]
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
I have been experimenting with htaccess files. What would be the reason for using anything other than a basic file?
There are so many important things your can do with your htaccess file, the basic file here is just to get you started.