Advertisement

Home Web Hosting Guides General Information Article

5 htaccess Tricks Every Webmaster Should Know

Page Visited Visited: 3734
Not rated
Rate:

by Carlos Foster
April 24, 2008


Carlos Foster

Carlos Foster is the founder and president of Illmatic, a small web application development shop based in New York City. He started the company in 1998 with their first product, Illmatic's CGI Password Script, a simple program that helped webmasters manage their members. In 2000, Illmatic launched a popular, automated password protection system called Password Administrator. 2004 saw the release of Password Robot, a powerful password protection application.



Carlos Foster has written 1 articles for HostReview.
View all articles by Carlos Foster...

Here are 5 sets of htaccess directives every webmaster should know:

1 - Redirect Visitors While You Update Your Site

Update and test your site while visitors are redirected to the page of your choice:

order deny,allow
deny from all
allow from 123.123.123.123

ErrorDocument 403 /page.html

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

Replace 123.123.123.123 with your IP address. Also replace page.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 in plain language and links visitors to your home page. Here’s how to use your own 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 /old.html http://yoursite.com/new.html

Using a 301 redirect also ensures the page doesn’t lose its search engine ranking.

4 - Prevent Directory Browsing

When there’s no index page in a directory, visitors can look and see what’s inside. 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 friendlier?

http://yoursite.com/about
http://yoursite.com/pages/about.html

When it comes to URLs, as long as the meaning is clear, shorter 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/about.html” whenever anyone visits “http://yoursite.com/about”. Here are a few examples:

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

There’s a lot more to mod_rewrite and htaccess. Check out the author's blog at passwordrobot.com/blog for more details and tricks.

            Hosting Bookmarks   


Submit Your Articles or Press ReleaseAdd comment (Comments: 0)  

Advertisement