LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache add Response Header based off of requested URI (http://www.linuxquestions.org/questions/linux-server-73/apache-add-response-header-based-off-of-requested-uri-4175446073/)

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 http://www.example.com/ however Wordpress rewrites the request to http://www.example.com/index.php. I tried using a LocationMatch directive in conjunction with a Headers like this:

Code:

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

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

Code:

<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>.

Ideas?

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.

Code:

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



All times are GMT -5. The time now is 04:03 AM.