Solved

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

Posted on 2002-07-26
10
277 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
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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now