Apache

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:

REMOVE PHP HTML Extensions From THE URL :

For PHP

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


For HTML

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"
</IfModule>

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"
</IfModule>

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

XsoftHost Support

Share

Recent Posts

Add Extra IP addresses to server configuration On Ubuntu 17.10 and later

Each failover IP address will need its own line in the configuration file. The configuration…

4 years ago

Create RAID Arrays with mdadm on Ubuntu

What is mdadm? The mdadm utility can be used to create and manage storage arrays…

4 years ago

How to change the maximum upload file size for PHP

There are several scenarios that you might need to increase or decrease your php maximum…

6 years ago

How to install Let’s Encrypt Plugin in WHM/cPanel

What is Let’s Encrypt? Let’s Encrypt is a free certificate authority provided by the Internet…

6 years ago

How to install python in my cPanel and add py extension

Python normally installed on all cPanel hosting server because most of Centos/red hat update system…

6 years ago

How to install and enable GUI GNOME Desktop on centos 7

Usually CentOS 7 comes in a numbers of variants, For most users, there are two…

6 years ago