.htaccess - htaccess 永久重定向抛出内部服务器错误

标签 .htaccess redirect mod-rewrite apache2.2 http-status-code-308

mod_rewrite documentation对于 Apache 2.2,RewriteRule [R] 标志状态:

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.

但是下面的代码片段似乎只允许“符号名称”:

# 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]

错误日志显示:

[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'

但是,308 似乎是永久重定向的 HTTP 状态代码:https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308

这是 Apache 中的错误还是我做错了什么?

最佳答案

您的 apache (2.2) 版本不能使用 308。在 apache 2.4.3 中添加了对 308 状态的支持:https://archive.apache.org/dist/httpd/CHANGES_2.4.3

core: Add missing HTTP status codes registered with IANA.

关于.htaccess - htaccess 永久重定向抛出内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44146566/

相关文章:

php - 使用 htaccess 生成 seo 友好的 url

apache - 使用 htaccess 记录外部 CDN 缓存的图像文件名

php - 服务器为肯定存在于正确目录中的资源提供 410 错误

ios - WKWebview 注入(inject) cookie header 导致重定向循环

mod-rewrite - SSL 重写重定向 apache2

ruby-on-rails - 在 Controller rails 中的 redirect_to 之前检查 url 的状态代码

php - 子目录中的 htaccess 重写库

PHP 代码确定用户是否被 301 重定向到我的网站

php - .htaccess错误: The requested URL was not found on this server

.htaccess - .htaccess 上的 URL 重写