• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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


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
M031097
Asked:
M031097
1 Solution
 
samriCommented:
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
 
M031097Author Commented:
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
 
samriCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
M031097Author Commented:
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
 
ahoffmannCommented:
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
 
samriCommented:
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
 
M031097Author Commented:

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
 
BigRatCommented:
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
 
periwinkleCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now