https://help.superhosting.bg/en/http-status-code-301-permanent-302-temporary.html
  • bg
  • en

Hosting, Domains, Cloud, Virtual Private Servers (VPS), Managed VPS, SSL Certificates

HTTP status codes - 301 (Moved Permanently) & 302 (Found)

FAQ
301, 302, http 301, http 302, status 301, status 302, redirect 301, redirect 302, 301 permanent, 301 permanently, 301 302, 301 redirect 302, 301 moved permanently, 302 found, 302 moved temporarily

301 Moved Permanently and 302 Found are HTTP status codes sent in response to web clients and search engine bots when trying to access a redirected URL.

The HTTP status code is the first line in HTTP headers used in a web server response. 301 and 302 codes are described in details in the HTTP specification.

301 Moved Permanently

A 301 status means that the page has been permanently moved to another URL. Web clients should not access the old URL anymore and from now on they will be using the new one.

When this status is received, search engines (Google, Bing) will replace the old URL with the new one in their database. From then on, the search engine results will display only the new URL.

When there is a 301 redirect from sourcedomain.com to targetdomain.com, the web client and the server will exchange the following HTTP headers:

The browser requests loading sourcedomain.com with the sample HTTP request headers:

Request-Line GET / HTTP/1.1
HTTP headers (request)
web browser
Host: sourcedomain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Firefox/46.0
Accept: text/html,application/xhtml+xml

The server will respond to the request with these HTTP headers:

Status Line HTTP/1.1 301 Moved Permanently
HTTP headers (response)
web server
Date: Fri, 16 May 2016 12:20:50 GMT
Server: Apache
Location: http://targetdomain.com/

The browser, in this case Mozilla Firefox, will read this response and send a new request to the URL in the Location field. It will also replace sourcedomain.com in the bookmarks with targetdomain.com.

When to Use 301 Redirect?

- When the website's domain is changed; for example, when mysitename.com/blog from now on will be blog.mysitename.com or somesitename.com will be mysitename.bg;

- When a certain website is accessed from a few different URLs, such as: http://home.mysitename.com, http://www.mysitename.com, http://mysitename.net (parked domains), etc.;

- When the website will be using a new structure and new URLs.

302 Found

A 302 status means that the page is temporarily located on a different URL. Web clients must keep using the original URL.

When to Use 302 Redirect?

- Only when the redirect is really temporary;

- For example, when short maintenance is performed or access to the web source is temporarily restricted;

- In cases when a webpage is not ready to be published yet, but you would like to display something instead of it for a while (a coming soon page or something else).

Setting Up a 301 or 302 Redirect

Under the (Domain) Redirects menu in cPanel you can setup automatic redirects for domains and URLs. You can also use the Aliases menu in cPanel to redirect an alias.

Redirect might be implemented by setting up rules in the .htaccess file.

If you setup a redirect through .htaccess, you might need to clear the browser cache, in order to see the results.

HTTP status codes are part of the HTTP headers and can be managed by the applications in the hosting account. For example, setting up a 301 redirect by using a PHP code:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://targetdomain.com/new.html");
exit();
?>

500px270px
SuperHosting.BG
    FAQ
  • Redis Features and Support
    Redis (REmote DIctionary Server) is an open-code project similar to Memcached that enables you to store data. The tool is used to speed up website loading by caching data and... »
  • Most Used Ports
    This is a list of the most commonly used ports, which you can use to access the specified services. In the tables are described the services (or protocols), connection type... »
  • What is the Difference Between Visitors, Visits, Pageviews and Hits?
    The answer of this question is that a user might make many visits, one visit might consist of many pageviews and a page might generate a number of hits. Very often... »
  • What is a DDoS Attack?
    DDoS is a distributed denial of service attack. It is realized in the World Wide Web and affects mainly online services. DDoS attacks may assault websites, email services, eCommerce, e-banking, games, online payment... »
  • I/O (Input/Output Operations)
    In computing, communication between two processing systems is based on Input-Output operations. For example, input operations are the signals/data sent from a CPU or another type of controller towards a... »
All rights reserved © 2005-2017 , www.superhosting.bg