7

I am trying to set a header based on the URI of a particular page.

I access a page using chrome. Inspect element and see that my URI header is giving the value /bst/index.html Now in my Apache config , I want to set a Header to Yes if my %{REQUEST_URI} is equal to /bst/index.html This is what I am doing :

RewriteCond %{REQUEST_URI} ^\/bst\/index\.html [NC]
Header set X-Akamai Yes

The above config is not working and is setting X-Akami for all the pages I am visiting on the web page.

Any idea why ?

Jason Stanley
  • 91
  • 1
  • 1
  • 4

3 Answers3

5
<If "%{REQUEST_URI} =~ m#^/bst/index\.html#">
Header set X-Akamai Yes
</If>

Documentation and Documentation

Florin Asăvoaie
  • 7,057
  • 23
  • 35
0

For me %{THE_REQUEST} worked better liked this (I changed the regex of "Nestor Urquiza":

<If "%{THE_REQUEST} =~ m# /bst/index\.html#i">
  Header set X-Akamai Yes
</If>
0

%{REQUEST_URI} will probably just match the last path in the URI (index.html). You probably want to try with %{THE_REQUEST} instead:

<If "%{THE_REQUEST} =~ m#^/bst/index\.html#">
  Header set X-Akamai Yes
</If>
  • `THE_REQUEST` expands to the full browser request line, including the request method, so this will **never** match. [Check here](https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond) – flaviovs Mar 21 '20 at 00:47