advertise with ongsono.com
 

Useful HTACCESS Examples

Posted on Saturday, 26 January 2013


Create a 404 Error Page

The 404 or Not found error tells that the client didn't get the requested file. And the default error page is displayed. We can create a custom error page using following code in .htaccess file and creating and error page named 404.php in following example.

Create a 404.php file in the root and put the following code in .htaccess file. It will display the customized error page.
ErrorDocument 404 /404.php

Redirect non WWW to WWW
RewriteEngine On RewriteCond %{HTTP_HOST} example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]


Rewrite dynamic urls to look like static urls
RewriteEngine on RewriteRule ^product-([^/]+).\html$ product.php?type=$1 RewriteRule ^user/([^/]+)$ users.php?name=$1
The output of above rewrite examples will be

http://example.com/product-car.html
http://example.com/user/altaf 

Allow or Deny specific IP Addresses
order allow,deny deny from 122.16.219.88 deny from 168.35.210.15 allow from all
Allow or deny specific IP Addresses using above code. Put your list of IP Addresses as given above.


Cache files using htaccess
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=31449600, public" </FilesMatch>
Set an expiration for cache files using above code.


Disable directory listing using htacess

Directory listing may be a potential security risk on your site. When you enter any address of a directory into the browsers address bar, all files and folders af that directory are listed by default. To prevent this listing you can put a small piece of code in .htaccess file as follows.
Options -Indexes

Read more about Useful HTACCESS Examples



Related read :

35 Incredible Surreal Photography Examples
Surreal Photography was developed following the 1st Planet War and it is inserted from the André Breton. This kind of photography is far more than the actual, which use to symbolize the dreams as
30 Stunning Examples of Mermaid Tattoos
The notion and the concept of the mermaid tattoos has constantly sailors attributed to the first centuries and folklore. They were the ones who made known this genuinely beautiful and mythical
18 Examples of Delightful Atmosphere with Turquoise Color in Your Home
If you want quiet, bright place full of inspiration, use this color in your home. For many people turquoise color is a favorite color and they say it is a color that is impossible not to like. It can
Stunning Flyer For your inspiration - 30 examples
Flyers play an important role when you are promoting your product. They improve the promotion element. But if you want to measure a person's attention on your flyers to, you would have to create