Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 01-17-2013, 03:27 PM   #1
LQ Newbie
Registered: Apr 2008
Location: MD
Distribution: CentOS, Fedora
Posts: 23
Blog Entries: 1

Rep: Reputation: 1
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>.

Old 01-17-2013, 04:03 PM   #2
LQ Newbie
Registered: Apr 2008
Location: MD
Distribution: CentOS, Fedora
Posts: 23
Blog Entries: 1

Original Poster
Rep: Reputation: 1
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


apache22, http, mod_rewrite

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
No response requested. Just making introducing myself jernest1 Member Intro 2 09-22-2009 12:01 PM
add header/footer to all pages via apache proxy kz26 Linux - Networking 0 05-18-2006 06:03 PM
cannot restrict apache to listen to LAN only. httpd2: (99)Cannot assign requested add Emmanuel_uk Linux - Networking 2 02-01-2006 03:31 PM
Apache auto-indexing - add header to every page... kasl33 Linux - Software 0 01-05-2006 11:11 AM
Apache config file to add header and footer mindstormsguy Linux - Software 2 05-02-2004 12:48 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration