2

I want to set the HTTP return code through a .htacces directive. So I was wondering if this is possible, as mod_headers states it expects: Name "Value".

If not what would be a good way to send a "HTTP/1.1 451 Redirect" using only .htaccess?

I want to redirect an ActiveSync on a host without server side scripting. So I only have .htaccess and static files.

Thanks!

JavaJens
  • 360
  • 1
  • 3
  • 14
  • _“So I was wondering if this is possible, as mod_headers states it expects: Name "Value".”_ – are you talking about the description of the `Header` directive? If so, it says `[value]` there, not `value`. And since when is 451 a redirect? Wikipedia lists it as `451 Unavailable For Legal Reasons (Internet draft)` – CBroe Nov 10 '13 at 11:50
  • Read a line below that. It says 451 Redirect (Microsoft). I assume it is propiertary, hence apache doesn't understand that. I need to set the status code "HTTP/1.1 451 Redirect". I believe it is [value] as it is optional for some directives. – JavaJens Nov 10 '13 at 11:57
  • Ah OK. Well, then what’s the actual problem? – CBroe Nov 10 '13 at 12:17
  • That I don't know how to set the response code to 451. – JavaJens Nov 11 '13 at 12:41
  • You put it into the `Header` directive where it says _header_ in the description. – CBroe Nov 11 '13 at 13:40
  • What action should I use then? And how should I encode it? In quotes? set, append, merge and add require a value, which I don't need. If you could provide me with the full line I need to paste, I would greatly appreciate it. – JavaJens Nov 11 '13 at 17:43
  • Well which action makes the most sense? The _header_ you want to send is `status`, and the value is `451` of course. – CBroe Nov 11 '13 at 20:51
  • Apparently I was too stupid for that. I believe I did excactly this, that is why I was so suspicious to your solution, but I guess I made a typo somewhere. If you post this as an answer I will select it. Thanks! – JavaJens Nov 11 '13 at 20:58

3 Answers3

4

Once I needed to set the HTTP response status code just like that for whole domain in .htaccess file:

RewriteRule ^ - [R=410,L]

So this way it works now for me on Apache 2.4

William Desportes
  • 1,412
  • 1
  • 22
  • 31
Kubo2
  • 331
  • 3
  • 16
0

RewriteRule can use non-3xx codes in the [R=xxx] flag. It should come pretty close.

covener
  • 17,402
  • 2
  • 31
  • 45
  • 1
    I tried using R=451, but apache2 said: RewriteRule: invalid HTTP response code '451' for flag 'R'. Where did you find it saying that you can use non 3xx codes? Maybe this is a bug in my apache? – JavaJens Nov 11 '13 at 12:42
  • @JavaJens Might be. What version of Apache are you using? – Kubo2 Feb 25 '16 at 06:46
  • @Kubo2 This was two years ago ;) I resolved the issue and can't remember. Thx though! – JavaJens Feb 25 '16 at 07:39
0

Well which action makes the most sense? You want to send a status header, and two of them or appending to an existing one would not make sense, so you want to use set.

And the value is 451 of course. You can put any text behind that if you want to, but status code textual descriptions in HTTP are pure “sugar” for human readability, and any client has to ignore anything else but the numeric code.

CBroe
  • 91,630
  • 14
  • 92
  • 150