A lot of stuff and things…

Common Apache .htaccess Rules

Some little .htaccess tricks to help you along the way 🙂

1. The following will disallow the execution of file’s with extensions you specify.

Options -ExecCGI
AddHandler cgi-script .pl .py .php .jsp. htm .shtml .sh .asp .cgi

2. The following will force files to download with a specific extension.

AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4 

3. The almighty 301 redirect! Redirect certain files to somewhere else.

Redirect 301 /original/filename.html

4. Want visitors to go to mynewpage.php instead of index.html/php/htm etc…? Here you go!

DirectoryIndex mynewpage.php

5. Stop hotlinking. ie, other people stealing your images and your bandwidth:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://([ -a-z0-9]  \.)?domain\.com [NC]
RewriteRule \.(gif|jpe?g|png)$ - [F,NC,L] 

6. Want to stop using those old flunky oem error pages? Use the following!

ErrorDocument 500 /500.php
ErrorDocument 401 /401.php
ErrorDocument 404 /404.php 
ErrorDocument 403 /403.php

7. Redirect all traffic to ssl:

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

Hope this helps!

Next Post

Previous Post

Leave a Reply

© 2021

Theme by Anders Norén