1

I wish to set a response header in .htaccess but only when the site is loaded over HTTPS:

Header set MyHeader "%D %t" "%{HTTPS:on}"
# Error: Unknown parameter: %{HTTPS:on}

Header set MyHeader "%D %t" "expr=%{HTTPS:on}"
# Error: syntax error, unexpected $end: Function 'HTTPS' does not exist

Header set MyHeader "%D %t" "expr=%{HTTPS}==on"    
# Error: syntax error, unexpected $end, expecting '('

HTTPS is listed as a variable here

PS: I'm having a really hard time understanding how Apache expressions work so if anyone has come across a simple introduction with good examples, please share.

1
  • Why the downvote? Did I break a rule? Sep 15, 2016 at 0:50

1 Answer 1

2

Use an <If> clause, it should work in .htaccess:

<If "%{HTTPS} == 'on'">
    Header set MyHeader "%D %t"
</If>

Reference:
http://httpd.apache.org/docs/2.4/mod/core.html#if

1
  • 1
    Hi Jonah. Thanks, +1. I got it to work in a single line as the title requested. I just needed to use my last rule from the OP but replace on with 'on' Sep 15, 2016 at 2:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .