Display Ads On This Blog

Banner Ads on scriptforphp.blogspot.com
Provides free php script for php developer.
Prix: € 5.00

Tuesday, February 9, 2010

htaccess redirect invalid url to error page

Contact Us

Hire PHP Web Developer


If you are new to htaccess , Create htaccess file by rename any file with ".htaccess" name.

Now you can write rules & conditions for invalid urls

Some common error code:
  • 401 - Authorization Required
  • 400 - Bad request
  • 403 - Forbidden
  • 500 - Internal Server Error
  • 404 - Page Not Found
To redirect to error page we can use following :

Syntax :

ErrorDocument ERROR_CODE /ERROR_REDIRECT_FILE.html

Examples :

ErrorDocument 404 /error_404.html

ErrorDocument 500 /somefolder/error_500.html


Some More Examples

  • RewriteRule ^/$ /homepage.html [L]
  • RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(.+)errata\.html?$ cgi-bin/errata/errata-html/$1

    (Rewrites can be conditional, for example, rewrite only if the file could not be found: )
  • RewriteRule ^(.*)/(.*)$ index.php?param1=$1¶m2=$2 [L]

    (Match if url passed like "http://www.mysite.com/value1/value2/" then redirect to http://www.mysite.com/index.php?param1=value1¶m2=value2)

Note : If you have any query or questions about htaccess programing kindly post your comments 

0 comments:

Post a Comment