Solved

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

Posted on 2002-07-26
10
280 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

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 …
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

11 Experts available now in Live!

Get 1:1 Help Now