Wednesday, June 1, 2011

What is .htaccess File? How .htaccess can be Used for 301 Redirection and 404 Error Page?

What is .htaccess File?

.htaccess file is hidden file which can be read by search engines. If you want to use redirection in your website then you can use this file. It can be made in note pad with name .htaccess

Example: If you want to redirect your website to htp://example.com to http://www.example.com then you can use .htaccess file in your website.

.htaccess file should need to locate in the root of directory.

Format of .htaccess file

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

.htaccess file is helpful for 301 Redirection

If you want to redirect any of your website page then you can use 301 redirection in this file

Example: If you want to redirect your page http://www.example.com/index.html to http://www.example.com then you can use by the following method

Redirect 301 /index.html http://www.example.com/

It will redirect index.html to you home page

.htaccess file is helpful for 404 Error Pages

If your website pages are not working and giving 404 error page then you can use .htaccess file by redirecting method same as that of above

Suppose your page http://www.example.com/404-error-page.html is not working then you can use 301 redirection as follows

301 Redirect
/404-error-page.html http://www.example.com

It will redirect your error page to home page of your website.


Note: .htaccess file can be implement to only Linux Server not in Windows Server

No comments:

Post a Comment