Categories
Linux

Apache : Usefull .htaccess Configurations

Apache Usefull .htaccess Configurations

I came across the following useful .htaccess configuations over at https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess#L169.

Rewrite www.cb-net.co.uk -> cb-net.co.uk
{code lang:ini showtitle:false lines:false hidden:false}<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>{/code}
 
Conversley rewrite cb-net.co.uk -> www.cb-net.co.uk
{code lang:ini showtitle:false lines:false hidden:false}<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>{/code}
 
Protect access to backup files, including Akeeba backup files for Joomla
{code lang:ini showtitle:false lines:false hidden:false}<FilesMatch “(\.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist|jpa)|~)$”>
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>{/code}
 
Prevent access to hidden files
{code lang:ini showtitle:false lines:false hidden:false}<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} -d
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule “(^|/)\.” – [F]
</IfModule>
{/code}

Leave a Reply

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