.htaccess Tips and Tricks

Oct 22, 2013, by admin

Hi all here today we are going to see some useful .htaccess Tips and Tricks

1) Redirect your website visitors while you update or test your website

order deny,allow
deny from all
allow from 117.117.117.117

ErrorDocument 403 /showpage.html

<Files showpage.html>
allow from all
</Files>

Replace 117.117.117.117 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?

http://yourwebsite.com/about
http://yourwebsite.com/pages/aboutus.html

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

RewriteEngine on
RewriteRule ^aboutus/$ /pages/aboutus.html [L]
RewriteRule ^features/$ /features.php [L]
RewriteRule ^buy/$ /buy.html [L]
RewriteRule ^contactus/$ /pages/contactus.htm [L]

Hope the post will be useful for you all to get more updates like the page Bugtreat Technologies to get instant updates of our templates like the page Cs Cart templates