?
Solved

Customize HTTP-headers (  %{HTTP:header}  )

Posted on 2002-07-26
10
Medium Priority
?
309 Views
Last Modified: 2010-03-04

Hello

I have some customized HTTP-headers that I want to use. I send information about the user and want to change the URL dependin on this header. I have found that I can use
RewriteRule and use %{HTTP:header} (unfortunalty that only works on the ordinary headers like Host, Location).
ex.
RewriteRule ^/(.*) /%{HTTP:MyHeader}/$1
doesn't work, output is www.mydomain.com//

RewriteRule ^/(.*) /%{HTTP:host}/$1
output is www.mydomain.com/www.mydomain.com/


is there anyway I can add these headers in apache so it
finds them. (does this make sense?)
or should I be using a perl-script instead? I'm not that good at perl scripts though.

TIA
/M
0
Comment
Question by:M031097
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 15

Expert Comment

by:samri
ID: 7184566
M,

Taka a look at mod_headers module. http://httpd.apache.org/docs/mod/mod_headers.html

And subsequently, you can use you cgi scripts, or SSI to examine this header and act accordingly.

cheers.
0
 

Author Comment

by:M031097
ID: 7184600
Hi Samri

mod_headers seems to be for adding, removing headers not getting their values.

Regarding scripts...well...like I said, not that good at them. Guess I have to learn that too then.

/M
0
 
LVL 15

Expert Comment

by:samri
ID: 7184641
M,

depending on what you want to do; I am afraid that you might have to start working on CGI scripts.  With CGI, you can even sent HTTP header on response to client request.

mod_rewrite can do it, but I doesn't have that much knowledge (too tricky to work on.).

If you insist on working on mod_rewrite, please take a look at Rewriting Guide on Apache website.
http://httpd.apache.org/docs/misc/rewriteguide.html

There is a number of examples that make use of HTTP Header.  Perhaps on would match what you intend to use.

cheers.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:M031097
ID: 7184655
Samri,

yes I have been looking at the Rewriting Guide, but haven't found anything on getting the value of a header that I have set. Still loking though...

regards
/M
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7184798
hat do you want to do with the HEADER information?
Is it just to controll the URL, then mod_env and mod_setenv might be what you're looking for.

Something like:

     SetEnvIf Request_URI "/whatever/"  myvariable
   
and then in <Directory>

     Allow from all env=myvariable
0
 
LVL 15

Expert Comment

by:samri
ID: 7184856
M,

Please taka a look at mod_rewrite docs;
http://httpd.apache.org/docs/mod/mod_rewrite.html
http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteCond

Some example;

RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*
RewriteRule  ^/$                 /homepage.max.html  [L]

RewriteCond  %{HTTP_USER_AGENT}  ^Lynx.*
RewriteRule  ^/$                 /homepage.min.html  [L]

RewriteRule  ^/$                 /homepage.std.html  [L]


Also take a look at how you could try something with CGI.pm module;
http://www.perldoc.com/perl5.6.1/lib/CGI.html
0
 

Author Comment

by:M031097
ID: 7184893

ahoffman:
No, I want to get the value of a specific header (that I have inserted previously). Even if I kan use SetEnvIf and find the header, I cannot get the value of the header (if I understand it correctly)

samri:
I have looked at the documents, but nothing helps (at least not what I've found)
Like I said, the header I am looking for is something I have added, so the ordinary pre-defined headers doesn't help.
I can use HTTP:<then the header name> to find the headers and I thought I could find my own header as well, but unfortunatly it didn't work
ex:
RewriteRule ^/(.*) /%{HTTP:MyHeader}/$1
doesn't work, output is www.mydomain.com//

notice the // at the end, compared to below:

RewriteRule ^/(.*) /%{HTTP:host}/$1
output is www.mydomain.com/www.mydomain.com/

where it inserted: www.mydomain.com
0
 
LVL 27

Accepted Solution

by:
BigRat earned 800 total points
ID: 7304829
According to the mod-rewrite docu :-


There is the special format: %{HTTP:header} where header can be any HTTP MIME-header name. This is looked-up from the HTTP request. Example: %{HTTP:Proxy-Connection} is the value of the HTTP header ``Proxy-Connection:''.

Your header is NOT a standard MIME header. In CGI such no standard headers are prefixed with HTTP_

From http://hoohoo.ncsa.uiuc.edu/cgi/env.html :

In addition to these, the header lines received from the client, if any, are placed into the environment with the prefix HTTP_ followed by the header name. Any - characters in the header name are changed to _ characters. The server may exclude any headers which it has already processed, such as Authorization, Content-type, and Content-length. If necessary, the server may choose to exclude any or all of these headers if including them would exceed any system environment limits.

HTH
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 9691105
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area with the following recommendation for this question:

Answered by BigRat

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

periwinkle
EE Cleanup Volunteer
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question