Types of Redirects – HTACCESS Redirect Tips and Tricks

Index

301 redirect:

This method is a permanent redirect method used for indicating a search engine to move from originating URL to new URL permanently. This method is the best for implementing URL redirect for the website. Here, code 301 represents the HTTP status code for the web.

Note:

This method is the most friendly website redirection method for search engines.

Syntax:

RewriteEngine on
RewriteCond %{http_host}^yourdomain.com[nc]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]

Note: Replace yourdomain.com with your domain name.

This method is used for the following purpose:

  1. People access the website with multiple URLs.
  2. It is used for moving sites to the new domain and make the transition as smooth as possible.
  3. It is also used for merging different websites.

302 redirect:

This method is a temporary redirect method. It is mainly useful for SEO purposes. When the user has a temporary landing page, and user plans to switch back to the main landing page after time.

Example:

Redirect www.errorsea.com to http://demo.errorsea.com using this method

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.errorsea\.com$ [NC]
RewriteRule ^(.*)$ http://demo.errorsea.com/ [L,R=302]

This method is used for the following purpose:

  1. We can get client feedback on a new page without affecting site ranking.
  2. A/B testing of a web page for checking design or functionality.
  3. We can update a web page while providing users with a consistent experience.

303 redirect:

This method uses the GET method. It informs the server to fetch the information on the server.ย 

Note:

This method was used for preventing a form resubmission after the HTTP POST request.

Suppose the user bookmarks the page, then it doesn’t show the user data submitted. Instead of that, this method shows him/her a page saying like “your data submitted successfully.”

This method is used for the following purpose:

  1. Device targeting
  2. Tracking
  3. A/B testing
  4. Geotargeting
  5. Recurring temporary content
  6. Redirect with no effect to the presence in search results

307 redirect:

This method is also a temporary redirect method like 303 redirects, but it is a non-cacheable method as default.ย 

We can use this method when we need to temporary redirect to new URL preserving the requests methods of the original URL request.

Note:

If the redirect is permanent, then this method should be avoided.

It shouldn’t use with PRG pattern.

308 redirect:

This method is cacheable by default if the user doesn’t indicate it. This method can be used if we require to handle the request method from the original request for the subsequent request.

For example, redirect of form action URLs using the POST method.

Note:

This method is the wrong choice for all occasions in which catchability can leads the user to unexpected negative behavior.

This method is used for the following purpose:

  1. Moving a domain permanently
  2. Moving a document permanently
  3. Moving a very complex website containing many forms and using the POST method.
  4. Changing a site’s structure forever.
  5. Changing a site’s protocol permanently.
  6. When subsequent request requires the POST method

Leave a Reply

Your email address will not be published. Required fields are marked *

More in How To, PHP
Remove Element JavaScript
Remove Element JavaScript

With JavaScript, We can easily remove different HTML elements. Also Read: Create Element JavaScript Example 1 Suppose we want to...

Close