LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 01-17-2013, 04:27 PM   #1
rubanek
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 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?
 
Old 01-17-2013, 05:03 PM   #2
rubanek
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.

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


Reply

Tags
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 LinuxQuestions.org Member Intro 2 09-22-2009 01:01 PM
add header/footer to all pages via apache proxy kz26 Linux - Networking 0 05-18-2006 07:03 PM
cannot restrict apache to listen to LAN only. httpd2: (99)Cannot assign requested add Emmanuel_uk Linux - Networking 2 02-01-2006 04:31 PM
Apache auto-indexing - add header to every page... kasl33 Linux - Software 0 01-05-2006 12:11 PM
Apache config file to add header and footer mindstormsguy Linux - Software 2 05-02-2004 01:48 PM


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

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