How to change the HTTP status of redirected content
When you redirect content with the Redirect, RedirectMatch and RewriteRule directives, for example, and you don't specify explicitly the HTTP status code of the redirected content, the temporary HTTP status code will be used. The temporary HTTP status code is 302.
If you want to, you can change the status code of the redirected content. You can do this by using one of the following words or its corresponding code:
- permanent-the permanent redirect status implies, as the name suggests, that the content has been moved for good. The status code that corresponds to this is 301.
- temp-the temporary status is the default one that's used if you don't specify any. It corresponds to status code 302 and indicates that the content has been moved for a period of time.
- seeother-corresponds to a See Other status and code number 303.
- gone-this status indicates that the content is removed and will no longer be available. The code number for this status is 410. When this status is used the destination URL address should be removed from the redirect directive.
When it comes to the Redirect and RedirectMatch directives you should put the word or the code right after the directive. For example, if you want to redirect the content from yourdomain.com/images to yourdomain2.com/images with a permanent redirect status, you can use the following directive:#Redirect yourdomain.com/images to yourdomain2.com/images with permanent status Redirect permanent /images http://yourdomain2.com/images
You can also use directly the status code number. The result would be the same. So, for example, the above directive is the same as:#Redirect by specifying the status code number Redirect 301 /images http://yourdomain2.com/images
As we mentioned, if you use the gone (410) status, you should remove the destination URL from the directive. Otherwise, the client will receive an internal server error. For example, if you have the following directive with a seeother (303) status:
RedirectMatch seeother ^/files/(.*)\.pdf$ http://yourdomain2.com/docs/$1.pdf
and you want to change the status to gone, then the directive would look like this:
RedirectMatch gone ^/files/(.*)\.pdf$
Of course, in such cases requests that match the path will not return any content to the client.
For information on how to redirect content with Redirect and RedirectMatch check out the article on redirecting content with the Redirect directive and the article on redirecting content with the RedirectMatch directive.
If you use mod_rewrite to redirect content, you can change the HTTP status code by modifying the R flag of the RewriteRule directive. To do this after the R flag put the symbol for equals and then the status code or its corresponding word (if there is such). For example:RewriteEngine On RewriteRule ^images/(.*) http://domain.com/images/$1 [R=301]
would change the HTTP status to 301 (permanent). That would be the same as:RewriteEngine On RewriteRule ^images/(.*) http://domain.com/images/$1 [R=permanent]