-   Linux - Server (
-   -   Apache add Response Header based off of requested URI (

rubanek 01-17-2013 04:27 PM

Apache add Response Header based off of requested URI
I need to insert a response header for my homepage. My site utilizes Wordpress (which isn't terribly relevant) but the fact that Wordpress relies heavily on mod_rewrite is. The homepage gets access at however Wordpress rewrites the request to I tried using a LocationMatch directive in conjunction with a Headers like this:


<LocationMatch "^/$">
    Header Always Set Captain Jean-Luc

That doesn't work, because of all of the rewrites that occur. If I start the LocationMatch block like this it will work:


<LocationMatch "^/index.php$">
The problem is that every page created in Wordpress utilizes ^/index.php$. So, I need a means of creating response headers based off of the originally requested URI.

LocationMatch seems to apply to the finally requested URI after mod_rewrite is done with it. I need a directive like <Orignally_Requested_URI>.


rubanek 01-17-2013 05:03 PM

Problem Solved
I managed to solve my own problem. I don't know if it's the most efficient way or not, but it's working the way I want.

Using mod_rewrite I check to see if the originally requested URI equals "^/$" and if it does I set an environment variable named "ISHOMEPAGE" to 1. Then I can set the header based on whether or not that environment variable exists.


    RewriteEngine On
    RewriteRule ^/$ - [E=ISHOMEPAGE:1]
    Header Always Set Captain "Jean-Luc" env=ISHOMEPAGE

All times are GMT -5. The time now is 05:16 AM.