.htaccesshttp-redirectmod-rewriteapache2.2http-status-code-308

htaccess permanent redirect throws Internal Server Error


In the mod_rewrite documentation for Apache 2.2, the RewriteRule [R] flag states:

Any valid HTTP response status code may be specified, using the syntax [R=305], with a 302 status code being used by default if none is specified. The status code specified need not necessarily be a redirect (3xx) status code. However, if a status code is outside the redirect range (300-399) then the substitution string is dropped entirely, and rewriting is stopped as if the L were used.

In addition to response status codes, you may also specify redirect status using their symbolic names: temp (default), permanent, or seeother.

However the following snippet of code only seems to allow the "symbolic names":

# Force HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off

# this works
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=permanent,NE]

# this doesn't work
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=308,NE]

The error log shows:

[Tue May 23 23:11:12 2017] [alert] [client 192.168.33.1] /var/www/html/ventus/.htaccess: RewriteRule: invalid HTTP response code '308' for flag 'R'

However, 308 appears to be the HTTP status code for permanent redirect: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308

Is this a bug in Apache or am I doing something wrong?


Solution

  • You can't use 308 with your version of apache (2.2). The support for 308 status was added in apache 2.4.3: https://archive.apache.org/dist/httpd/CHANGES_2.4.3

    core: Add missing HTTP status codes registered with IANA.