Link to home
Start Free TrialLog in
Avatar of M031097
M031097

asked on

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
Avatar of samri
samri
Flag of Malaysia image

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.
Avatar of M031097
M031097

ASKER

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
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.
Avatar of M031097

ASKER

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
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
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
Avatar of M031097

ASKER


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
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of periwinkle
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