Web Tips and tricks for .htaccess file
Main feature, a PHP web developer notice is the use of .htaccess file for a custom error page like 404,403 and more. This article provides you the tips and tricks on how .htaccess file can be used.
Tips and tricks includes with examples like creating custom error page through .htaccess file. .htaccess is txt file, can be edited in a notepad or any editor and it should be saved only with .htaccess without any character along the file name.
Below lines teaches you the more useful .htaccess features and the codes used to create .htaccess. Test the features by coping and pasting the codes you want into the text editor or notepad and save as .htaccess file and upload the file in web root directory of web server.
Here are some of the tips and tricks using .htaccess file
Custom Error page
If you remove a search engine indexed web page or renamed a web page and it displays as “page cannot be found” when a user comes through search engine listings, it is named as bad link and your website rate comes down. This can be avoided by creating custom error page
Create a custom error page with home page link or any other service page, so that the user can find the information he needs and will not go away from your website. The error code should be next to ErrorDocument and then the website with 404 error page
Redirects
If you are planning to shift your entire folder with the pages and media, images and other files into new folder of your server. Then there will be lot of custom error page. Here is a way out by .htaccess file redirect features. Suppose if your users redirecting from folder called tempfiles to another folder, the following code can be used
Where the first argument is the folder or filename that you
are trying to redirect people from, and where the second argument
is the file or directory you are trying to get people to go to
instead:
Here the first argument is filename or folder name you’re
trying to redirect user from and the second argument is the file
you’re trying to get users to go.
The above code is to know how the Redirect feature of .htaccess works.
Changing Home page/Index page
Users enter URL to your site, by default index.html or default.html similar page will load initially. Using .htaccess, loading file can be changed when website URL gets loaded.
From the above code, default page is been replaced by first.htm. When user visits your website by entering in the URL of your website, they will be directed to the default page you specify in the place of first.htm in the above code.
IP Blocking
This feature can prevent individual or a group of individuals from accessing your website by using IP range; you can deny access to them.
The below command format can be used for IP Blocking.
You can also add as lots of deny from lines of code as you want. And also by entering smaller portion of IP such as 15.2, you can block all IP’s with in that range. All IP’s 15.2.10.65, 15.2.50.134 and so will also be blocked automatically.
Please note IIS servers does not support .htaccess.



