1

I need to set some headers if REQUEST_URI contains the "compile" word.

My uri is:

http://myurl/compile/123456/123456?token=myvalue

This is the code in the .htaccess that DOES NOT work:

Header always set MyHeaderCompile myvalue "expr=%{REQUEST_URI} =~ /compile/"

This line does not set MyHeaderCompile header.

If I change the line with this:

Header always set MyHeaderCompile myvalue "expr=%{QUERY_STRING} =~ /token/"

It works.

Giacomo M
  • 131
  • 6

1 Answers1

2

I solved using THE_REQUEST instead of REQUEST_URI.

Thanks to this post https://stackoverflow.com/a/57379503/4641073 I read that REQUEST_URI can be changed from other directives, instead THE_REQUEST never changes.

The line that works is this:

Header always set MyHeaderCompile myvalue "expr=%{THE_REQUEST} =~ /compile/"
Giacomo M
  • 131
  • 6
  • I would imagine a request such as `/compile/123456/123456` requires _rewriting_ - this will change the value of the `REQUEST_URI` server variable. – MrWhite Dec 17 '19 at 18:23