htaccess tutorial

What .htaccess For

.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all sub directories

some configurations may you add to the file:



RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

REMOVE Libwww-perl Access Test

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]

In order to improve the security of your site against some types of XSS (cross-site scripting) attacks, it is recommended that you add the following header to your site:
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"

In order to add browser caching to your website, you will need to set the date for when the cache expires:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"

If you want to display custom Error Message on common error nubmer 404 the simplest way to set a 404 error page is by directly setting a 404 error message in the .htaccess file itself:

ErrorDocument 404 "SORRY Page not found"

or if you have custom Error 404 Like “404.html” Page you can simply add the following

ErrorDocument 404 /404.html

Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Related Posts