Most useful 5 htaccess tricks every webmaster should know
1) Redirect your website visitors while you update or test your website
deny from all
allow from 22.214.171.124
ErrorDocument 403 /showpage.html
allow from all
Replace 126.96.36.199 with your IP address. Also replace showpage.html with the name of the page you want visitors to see.
2) Display a custom 404 error page
Your server displays a “404 File Not Found” error page whenever a visitor tries to access a page on your site that doesn’t exist.
You can replace the server’s default error page with one of your own that explains the error and links visitors to your home page.
ErrorDocument 404 /404.html
Replace 404.html with the name of the page you want visitors to see.
3) Handle moved or renamed pages
You’ve moved or renamed a page on your site and you want visitors automatically sent to the new page when they try to access the old one.
Use a 301 redirect
Redirect 301 /oldpage.html http://yourwebsite.com/newpage.html
Using a 301 redirect also ensures the page doesn’t lose its search engine ranking, as you know how important it is.
4) Prevent directory browsing
When there’s no index page in a directory, visitors can look and see what’s inside (directory structure and page listing).
Some servers are configured to prevent directory browsing like this. If yours isn’t, here’s how to set it up:
Options All -Indexes
5) Create user friendly URLs
Which of the two URLs below looks good?
Shorter URL is always better.
With htaccess and an Apache module called mod_rewrite, you can set up URLs however you want. Your server can show the contents of “/pages/aboutus.html” whenever anyone visits “http://yourwebsite.com/about”. Below are few examples
RewriteRule ^aboutus/$ /pages/aboutus.html [L]
RewriteRule ^features/$ /features.php [L]
RewriteRule ^buy/$ /buy.html [L]
RewriteRule ^contactus/$ /pages/contactus.htm [L]