HTTP response status code 308 Permanent Redirect is returned by the server to indicate that the requested resource has been permanently moved to a new location.
Usage
When the 308 Permanent Redirect status code is received, clients are expected to update their stored links to the new URI. This will be specified by the Location HTTP header and can be used by the client for automatic redirection.
This message might be sent by servers that have migrated to a new domain, or have reorganized their internal file structure, and do not plan on reverting to the former URI.
The 308 Permanent Redirect status code differs from the 301 Moved Permanently status code in that the client is required to make an identical HTTP request to the specified Location, whereas 301 Moved Permanently allows for the client to change the HTTP request method. For example, in response to a POST HTTP request by the client, a 301 Moved Permanently HTTP response signals to the client that it is okay to change the POST HTTP request to a GET HTTP request for the subsequent HTTP request. However, 308 Permanent Redirect status code stipulates that if it was originally a POST HTTP request then the follow-up HTTP request also has to be a POST HTTP request.
Example
In the example, the client attempts to retrieve an HTML resource. The server responds to say that the resource has permanently moved to a new URI and includes it in the Location HTTP header. Client-side, a message is presented in the message body to suggest updating the relevant bookmarks, however this is seldom visible in modern browsers which straight away redirect to the new location.
Request
GET /news.html HTTP/1.1
Host: www.example.re
Response
HTTP/1.1 308 Permanent Redirect
Location: http//www.example.re/feeds/news.html
Content-Type: text/html; charset=UTF-8
Content-Length: 150
<h1>The Newsfeed has moved</h1>
<body>
The newsfeed has moved permanently to <a href=/feeds/news.html>here</a>. Please update your bookmarks.
</body>
Code references
.NET
HttpStatusCode.PermanentRedirect
Rust
http::StatusCode::PERMANENT_REDIRECT
Rails
:permanent_redirect
Go
http.StatusPermanentRedirect
Symfony
Response::HTTP_PERMANENTLY_REDIRECT
Python3.5+
http.HTTPStatus.PERMANENT_REDIRECT
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_PERMANENT_REDIRECT
Angular
@angular/common/http/HttpStatusCode.PermanentRedirect
Takeaway
The 308 Permanent Redirect status code indicates that the resource has moved to a new location that is specified within the HTTP response. Clients are expected to update their internal data accordingly and when making the follow-up HTTP request, they are not to change the HTTP request method.
See also
- 301 Moved Permanently
- 302 Found
- RFC 7538
Last updated: August 2, 2023
Jan 11, 2018 6:00:19 PM |
308 Permanent Redirect: What It Is and How to Fix It
A close look at the 308 Permanent Redirect response code, including troubleshooting tips to help you resolve this error in your own application.
A 308 Permanent Redirect message is an HTTP response status code
indicating that the requested resource has been permanently moved to another URI
, as indicated by the special Location
header returned within the response. The 308 Permanent Redirect
code was added to the HTTP standard relatively recently in April 2015, as detailed in the RFC7538 specification document for the 308
status code. As written in the RFC specification, the 308 Permanent Redirect
code was necessary to fill in the gap left with similar codes of 301
, 302
, and 307
.
There are dozens of possible HTTP status codes used to represent the complex relationship between the client, a web application, a web server, and the multitude of third-party web services that may be in use, so determining the cause of a particular HTTP response status code can be difficult. Since there are so many potential codes, each of which represents a completely different status or event, it can be difficult to differentiate between many of them and determine the exact cause of such errors, including the 308 Permanent Redirect
response code.
Throughout this article we’ll explore the 308 Permanent Redirect
code by looking at a handful of troubleshooting tips. We’ll also examine a few useful and easy to implement fixes for common problems that could be causing 308
codes to appear in your own web application. Let’s get down to it!
The Problem is Server-Side
All HTTP response status codes within the 3xx
category are considered redirection messages
. These codes indicate to the user agent (i.e. your web browser) that an additional action is required in order to complete the request and access the desired resource. The 3xx
response code category is distinctly different from the 5xx
codes category, which encompasses server error
messages. For example, the 503 Service Unavailable
error we explored a late last year indicates that a server is temporarily unavailable, or is unable to handle the request for some reason. Thus, while a 5xx
category code indicates an actual problem has occurred on a server, a 3xx
category code, such as 308 Permanent Redirect
, is rarely indicative of an actual problem — it merely occurs due to the server’s behavior or configuration, but is not indicative of an error or bug on the server.
The 308 Permanent Redirect
code is similar to the 301 Moved Permanently
code we explore in our 301 Moved Permanently: What It Is and How to Fix It article. As discussed in that post, the RFC1945 HTTP/1.0 specification document explicitly states that the 301
code should not necessarily inform user agents (i.e. browsers) to automatically redirect POST
HTTP method requests to GET
HTTP method requests. However, many user agents did erroneously change POST
requests to GET
redirect requests, which led to unintentional problems.
To handle this explicit allowance or denial of changing POST
requests to GET
requests the HTTP standards included the following codes:
- 301 Moved Permanently: The resource has been permanently moved and request method conversion from
POST
toGET
is allowed. - 307 Temporary Redirect: The resource has been temporarily moved and request method conversion from
POST
toGET
is forbidden. - 302 Found: The resource has been temporarily moved and request method conversion from
POST
toGET
is allowed.
As you can see, this set of three HTTP status codes is missing a code that indicates a permanent redirect that forbids POST
to GET
conversion. This is the exact role that the 308 Permanent Redirect
status code fulfills.
The appearance of a 308 Permanent Redirect
is usually not something that requires much user intervention. All modern browsers will automatically detect the 308 Permanent Redirect
response code and process the redirection action to the new URI
automatically. The server sending a 308
code will also include a special Location
header as part of the response it sends to the client. This Location
header indicates the new URI
where the requested resource can be found. For example, if an HTTP POST
method request is sent by the client as an attempt to login at the https://airbrake.io
URL, the web server may be configured to redirect this POST
request to a different URI
, such as https://airbrake.io/login
. In this scenario, the server may respond with a 308 Permanent Redirect
code and include the Location: https://airbrake.io/login
header in the response. This informs the user agent (browser) that the POST
request data (login info) was received by the server, but the resource has been permanently moved to the Location
header URI
of https://airbrake.io/login
.
It’s also important to distinguish the purpose and use-cases of the 308 Permanent Redirect
response code from many seemingly similar 3xx
codes, such as the 307 Temporary Redirect
we looked at in the past. The 307 Temporary Redirect
code informs the client that the passed Location
URI
is only a temporary resource, and that all future requests should continue to access the originally requested URI
. On the other hand, the 308 Permanent Redirect
message is permanent and indicates that the passed Location
URI
should be used for future (identical) requests.
Additionally, since the 308 Permanent Redirect
indicates that something has gone wrong within the server
of your application, we can largely disregard the client
side of things. If you’re trying to diagnose an issue with your own application, you can immediately ignore most client-side code and components, such as HTML, cascading style sheets (CSS), client-side JavaScript, and so forth. This doesn’t apply solely to web sites, either. Many smart phone apps that have a modern looking user interface are actually powered by a normal web application behind the scenes; one that is simply hidden from the user. If you’re using such an application and a 308 Permanent Redirect
occurs, the issue isn’t going to be related to the app installed on your phone or local testing device. Instead, it will be something on the server-side, which is performing most of the logic and processing behind the scenes, outside the purview of the local interface presented to the user.
If your application is generating unexpected 308 Permanent Redirect
response codes there are a number of steps you can take to diagnose the problem, so we’ll explore a few potential work around below.
Start With a Thorough Application Backup
As with anything, it’s better to have played it safe at the start than to screw something up and come to regret it later on down the road. As such, it is critical that you perform a full backup of your application, database, and so forth, before attempting any fixes or changes to the system. Even better, if you have the capability, create a complete copy of the application onto a secondary staging
server that isn’t «live,» or isn’t otherwise active and available to the public. This will give you a clean testing ground with which to test all potential fixes to resolve the issue, without threatening the security or sanctity of your live application.
Diagnosing a 308 Permanent Redirect Response Code
A 308 Permanent Redirect
response code indicates that the requested resource has been permanently moved to the new URI
specified in the Location
response header. However, the appearance of this error itself may be erroneous, as it’s entirely possible that the server is misconfigured, which could cause it to improperly respond with 308 Permanent Redirect
codes, instead of the standard and expected 200 OK
code seen for most successful requests. Thus, a large part of diagnosing the issue will be going through the process of double-checking what resources/URLs are generating 308 Permanent Redirect
response codes and determining if these codes are appropriate or not.
If your application is responding with 308 Permanent Redirect
codes that it should not be issuing, this is a problem that many other visitors may be experiencing as well, dramatically hindering your application’s ability to service users. We’ll go over some troubleshooting tips and tricks to help you try to resolve this issue. If nothing here works, don’t forget to try Googling for the answer. Search for specific terms related to your issue, such as the name of your application’s CMS or web server software, along with 308 Permanent Redirect
. Chances are you’ll find others who have experienced this issue and have (hopefully) found a solution.
Troubleshooting on the Server-Side
Here are some additional tips to help you troubleshoot what might be causing the 308 Permanent Redirect
to appear on the server-side of things:
Confirm Your Server Configuration
Your application is likely running on a server that is using one of the two most popular web server softwares, Apache
or nginx
. At the time of publication, both of these web servers make up over 84%
of the world’s web server software! Thus, one of the first steps you can take to determine what might be causing these 308 Permanent Redirect
response codes is to check the configuration files for your web server software for unintentional redirect instructions.
To determine which web server your application is using you’ll want to look for a key file. If your web server is Apache then look for an .htaccess
file within the root directory of your website file system. For example, if your application is on a shared host you’ll likely have a username associated with the hosting account. In such a case, the application root directory is typically found at the path of /home/<username>/public_html/
, so the .htaccess
file would be at /home/<username>/public_html/.htaccess
.
If you located the .htaccess
file then open it in a text editor and look for lines that use RewriteXXX
directives, which are part of the mod_rewrite
module in Apache. Covering exactly how these rules work is well beyond the scope of this article, however, the basic concept is that a RewriteCond
directive defines a text-based pattern that will be matched against entered URLs. If a matching URL is requested by a visitor to the site, the RewriteRule
directive that follows one or more RewriteCond
directives is used to perform the actual redirection of the request to the appropriate URL.
For example, here is a simple RewriteCond
and RewriteRule
combination that matches all incoming requests to airbrake.io
using the HTTP POST
method, and redirecting them to https://airbrake.io/login
via a 308 Permanent Redirect
response:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^airbrake.io$
RewriteRule ^(.*)$ https://airbrake.io/login$1 [R=308]
Notice the extra flag at the end of the RewriteRule
, which explicitly states that the response code should be 308
, indicating to user agents that the request should be repeated to the specified URI
, but while retaining the original HTTP method (POST
, in this case). Thus, if you find any strange RewriteCond
or RewriteRule
directives in the .htaccess
file that don’t seem to belong, try temporarily commenting them out (using the #
character prefix) and restarting your web server to see if this resolves the issue.
On the other hand, if your server is running on nginx
, you’ll need to look for a completely different configuration file. By default this file is named nginx.conf
and is located in one of a few common directories: /usr/local/nginx/conf
, /etc/nginx
, or /usr/local/etc/nginx
. Once located, open nginx.conf
in a text editor and look for return
or rewrite
directives that are using the 308
response code flag. For example, here is a simple block directive
(i.e. a named set of directives) that configures a virtual server by creating a redirection from airbrake.io
to airbrake.io/login
for POST
HTTP method requests:
server {
listen 80;
listen 443 ssl;
server_name airbrake.io;
if ($request_method = POST) {
return 308 https://airbrake.io/login$request_uri;
}
}
Return
directives in nginx
are similar to the RewriteCond
and RewriteRule
directives found in Apache
, as they tend to contain more complex text-based patterns for searching. Either way, look through your nginx.conf
file for any abnormal return
or rewrite
directives that include the 308
flag. Comment out any abnormalities before restarting the server to see if the issue was resolved.
Scour the Logs
Nearly every web application will keep some form of server-side logs. Application logs
are typically the history of what the application did, such as which pages were requested, which servers it connected to, which database results it provides, and so forth. Server logs
are related to the actual hardware that is running the application, and will often provide details about the health and status of all connected services, or even just the server itself. Google «logs [PLATFORM_NAME]» if you’re using a CMS, or «logs [PROGRAMMING_LANGUAGE]» and «logs [OPERATING_SYSTEM]» if you’re running a custom application, to get more information on finding the logs in question.
Debug Your Application Code
If all else fails, it may be that a problem in some custom code within your application is causing the issue. Try to diagnose where the issue may be coming from through manually debugging your application, along with parsing through application and server logs. Ideally, make a copy of the entire application to a local development machine and perform a step-by-step debug process, which will allow you to recreate the exact scenario in which the 308 Permanent Redirect
occurred and view the application code at the moment something goes wrong.
No matter what the cause, the appearance of a 308 Permanent Redirect
within your own web application is a strong indication that you may need an error management tool to help you automatically detect such errors in the future. The best of these tools can even alert you and your team immediately when an error occurs. Airbrake’s error monitoring software provides real-time error monitoring and automatic exception reporting for all your development projects. Airbrake’s state of the art web dashboard ensures you receive round-the-clock status updates on your application’s health and error rates. No matter what you’re working on, Airbrake easily integrates with all the most popular languages and frameworks. Plus, Airbrake makes it easy to customize exception parameters, while giving you complete control of the active error filter system, so you only gather the errors that matter most.
Check out Airbrake’s error monitoring software today and see for yourself why so many of the world’s best engineering teams use Airbrake to revolutionize their exception handling practices!
An IETF RFC draft The Hypertext Transfer Protocol (HTTP) Status Code 308 (Permanent Redirect) defines HTTP status 308 as Permanent Redirect. It should, of course, be noted that this is a draft document and contains in its document header the text «Expires: September 27, 2012», which I presume would mean it should be considered invalid now, but I’m not familiar with IETF’s processes and so don’t feel confident about this.
The Wikipedia article List of HTTP status codes uses this definition of 308, also:
308 Permanent Redirect (approved as experimental RFC)[12]
The request, and all future requests should be repeated using another URI. 307 and 308 (as proposed) parallel the behaviours of 302 and 301, but do not allow the HTTP method to change. So, for example, submitting a form to a permanently redirected resource may continue smoothly.
…
[12]: «The Hypertext Transfer Protocol (HTTP) Status Code 308 (Permanent Redirect)». IETF. 2012. Retrieved March 27, 2012.
Eric Law, of Microsoft at the time, comments on this HTTP/308 code in Pushing the Web Forward with HTTP/308. That caused me to discover that Firefox supports 308 under this meaning.
However, when I was looking in the python-requests library, I found that there is another usage of 308:
308: ('resume_incomplete', 'resume'),
This seems to come from a Google Gears resumable HTTP requests proposal, defining 308 Resume Incomplete
. There seems to be some usage of that. Of course, neither of these proposals acknowledges the existence of the other.
So what’s going on? Is 308 Permanent Redirect
alive? What’s happening with the status code 308? What should I do?
Have you ever been frustrated by a seemingly permanent redirect? The HTTP 308 Permanent Redirect can be the answer to your woes. It is an incredibly useful and powerful tool for web developers, enabling them to improve their website’s performance and user experience. This guide will provide a comprehensive overview of how this redirect works and why it should be used in certain situations.
HTTP 308 Permanent Redirect is an HTTP status code that lets a user agent know it needs to update the requested effective request URI with a preferred URI reference. It consists of an associated 3xx status code, typically delivered in response to a valid request from a client, where it contains a Location field value referencing the alternative resource that should be used instead.
For example, Suppose a user tries to access the following URL:
http://test.com/old-page
But they have permanently moved the content to a new URL:
http://test.com/new-page
In this case, the server will send an HTTP response with status code 308, indicating that the resource has been permanently moved. The response might look something like this:
HTTP/1.1 308 Permanent Redirect
Location: http://test.com/new-page
Content-Length: 0
This response tells the user’s browser that the resource they were trying to access has permanently moved to a new URL. The “Location” header indicates the new URL where the content can be found, and the “Content-Length” header is set to 0 since there is no actual content in the response. The user’s browser will then automatically follow the redirect and load the new page at the new URL.
This type of redirect is permanent; any future attempts by the client to access this resource will result in the same redirection being followed.
The 308 status code differs from other 3xx codes because its purpose is specifically to denote that the requested effective request URI has been replaced permanently, while still allowing for backward compatibility with older browsers. The server must return a permanent redirect when all requests are meant to be directed towards another page on the site or external domain completely. Thus, it serves as an indication to both web crawlers and users alike, informing them of changes made within their website’s architecture or content structure.
What Is The Difference Between A 308 Status Code And A 307 Status Code?
A 308 Permanent Redirect is an HTTP status code that informs search engines and other clients that the requested resource has been moved permanently. It differs from a 307 Temporary Redirect, which tells search engines to continue indexing the original URL for a limited amount of time. The differences between these two codes go beyond just their method definition; understanding them can be helpful when considering explicit cache controls and other web server configurations.
The most obvious distinction between a 308 Permanent Redirect and a 307 Temporary Redirect lies in their respective methods definitions: A 308 redirects all requests made to the originating page, regardless of whether they are GET or POST requests, while a 307 will only affect the current request type (e.g., if it was originally sent as a POST request). Additionally, with both types of redirection, you must use an absolute URI within the Location header field to indicate where the redirected resource should be found.
Finally, although they serve similar purposes of informing clients that a requested resource has been moved permanently or temporarily respectively, there are also some subtle differences between how search engines react to each type of status code. For example, Googlebot may take longer to update its index after encountering a 300-level status code than it does when dealing with certain 301 redirects — so keep this in mind when making your decision on which one is best suited for your website’s needs. Transitioning into the next section on what is the difference between a 308 status code and a 301 status code?
What Is The Difference Between A 308 Status Code And A 301 Status Code?
A 308 Permanent Redirect and a 301 Moved Permanently are two of the most common types of redirects. Both are HTTP response status codes that indicate the requested resource has been assigned a new permanent URI (Uniform Resource Identifier) and any future requests should be directed to this address instead.
The main difference between these two is in the way they communicate their message: while both have a short hypertext note, only one adds an additional field called ‘Location’, which provides the new URL where it can find what was originally requested. This addition allows for more flexibility when configuring redirection messages as browsers or clients only need to read the Location header to know where to go next.
In terms of implementation, a 301 will require changing the original http method from POST/GET/etc., whereas a 308 does not mandate such changes; all that’s necessary is returning the appropriate status code along with the Location header value. It’s worth noting that although both mean ‘moved permanently’, search engines tend to prefer 301 responses over ones with status code 308 due to its unambiguity.
When faced with deciding on which option to use, bear in mind that if you ever want your site visitors and search engine crawlers alike redirected immediately, opt for sending out a 301 Moved Permanently response since it offers them precise instructions about how and where exactly they should be going next.
What Is The Difference Between A 308 Status Code And A 302 Status Code?
The difference between a 308 status code and a 302 status code is one of the most important distinctions to keep in mind when using permanent redirects. An HTTP response status code indicates whether or not an action was successful; specifically, codes beginning with 3 indicate redirection. The distinction between these two codes lies in their permanency – a 302 status code signals that the target resource has only been temporarily moved while a 308 definitively states it has been permanently relocated.
HTTP Status Code | Usage |
---|---|
302 | Temporary Redirect – Post to Get |
308 | Permanent Redirect – Non-Standard |
Whereas a standard GET request can be resubmitted upon receiving a 302 status code, with a 308 response, any additional post requests will also result in redirection rather than updating the content. This makes sense since the page’s location has changed, meaning information sent after getting the initial response would be irrelevant to the new address. In other words, once you’ve received a 308 response from your server, you know for sure that all subsequent requests should go to the target URL specified by this message.
How To Use 308 Http Status Code For A Website?
As mentioned earlier the 308 HTTP status code is used for a permanent redirect, providing a response from the server that future references of an incomplete upload should use the new URI – or Uniform Resource Identifier. This means that when visitors attempt to access your website, they are automatically redirected to the new URL instead. As such, it’s important to understand how best to implement this particular status code into your web pages.
Here are five key points:
- Utilise permanent redirects so as not to confuse users with unnecessary multiple URLs;
- Ensure all structured data in linked pages has been updated accordingly;
- Include relevant meta tags and page titles on both old and new URIs;
- Use relative paths where possible – especially when migrating content between domains;
- Test out all changes before making them live on your site.
Give me a chart indicating whether web browsers support HTTP 308 status code. Include all the famous web browsers
Browser | Supports HTTP 308 Status Code |
---|---|
Chrome | Yes |
Firefox | Yes |
Edge | Yes |
Safari | Yes |
Opera | Yes |
Internet Explorer | No |
Other Similar Status Codes To The 308 Http Status Code
In addition to the 308 Permanent Redirect, other HTTP response status codes can be used in web applications. Clients with link editing capabilities should automatically re-link references to the effective request URI. The following table outlines some of these other status codes and provides details on their full support:
Status Code | Description | Support |
---|---|---|
301 | Moved Permanently | Full |
302 | Found (Previously “Moved temporarily”) | Partial(IE not supported) |
303 | See Other | Full |
307 | Temporary Redirect | Full |
The purpose of these different types of redirects is to allow changing the request type from one form to another without the user being aware of it. A permanent redirect will generally cause a client’s cache definition or explicit caching rules for that resource to become invalidated. Therefore, it is important for developers and system administrators to understand how best to use these various responses when creating web applications for their users. This guide has provided an overview about using the 308 Permanent Redirect HTTP Status code and its general uses cases as well as similar alternatives available when managing requests over the internet. With this information, readers now have a better understanding of how they can apply such techniques while developing robust applications across the web.
All HTTP status codes by categories
Код ответа состояния перенаправления 308 Permanent Redirect
протокола передачи гипертекста (HTTP) 308 указывает на то, что запрошенный ресурс был окончательно перемещен по URL-адресу, указанному в заголовках Location
. Браузер перенаправляет на эту страницу, и поисковые системы обновляют свои ссылки на ресурс (в «SEO-слове» говорится, что «сок ссылок» отправляется на новый URL-адрес).
Метод запроса и тело не будут изменены, тогда как 301
иногда может быть неправильно изменен на метод GET
.
Примечание. Некоторые веб-приложения могут использовать 308 Permanent Redirect
нестандартным образом и для других целей. Например, Google Диск использует ответ 308 Resume Incomplete
, чтобы указать клиенту, когда незавершенная загрузка остановилась. (См. Выполнение возобновляемой загрузки в документации Google Диска.)