h1

htaccess 302 ( temporary ) and 301 ( primary) redirects

August 22, 2008

There are permanent are temporary redirect methods that can be applied to .htaccess.

A permanent redirect will notify the visitor’s browser to update any bookmarks that are linked to the page that is being redirected. Temporary redirects will not update the visitor’s bookmarks.

Temporary Redirect ( 302 redirect )
########################################
RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ “http\:\/\/www\.domain\.com” [R=302,L]

###

Permanent Redirect ( 302 redirect )

##########################################

RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ “http\:\/\/www\.domain\.com” [R=301,L]

###

The above example will redirect domain.com to http://www.domain.com in browser.

.

About these ads

3 comments

  1. So, can you give an example of “why” you might need to use a 302 redirect over a 301 redirect? Would be really helpful!


  2. Please refer to http://www.hochmanconsultants.com/articles/301-versus-302.shtml for further details


  3. Tips:

    1. You should only use 302 redirects to set up temporary redirects, such as to clean up ugly URLs.
    2. If you want the URL to change in the search engine, use a 301 redirect.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: