Apache Server configuration support - HTTP_COOKIE problem

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > February 2006 > HTTP_COOKIE problem





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author HTTP_COOKIE problem
manoj.agarwal.in@gmail.com

2006-02-21, 7:50 am

Hi

I want to do some hash on the HTTP_COOKIE string which gives me a value
between 1 to 1000. For this I have written a PERL script. Now I want to
call this PERL script in my rewrite.conf (rewrite rule file) file in
apache. I am using RewriteMap for this but haven't succeeded. May be I
haven't understood using rewritemap well.
So my question is:

a. Can I reset my HTTP_COOKIE value in the rewrite.conf file?
b. Would calling a PERL script be a good idea for this or is there any
other way around?
c. Can I write the logic of hashing within my conf file?


My conf file looks like:

RewriteMap cookie1 prg:/home/y/share/htdocs/cookie1.pl
RewriteRule ^/(index.html)?$ ${bcookie:$1} [L,PT]

Am I doing something wrong in this?

rgds
Manoj

Duikboot

2006-02-21, 7:50 am

I am not sure, but shouldn't the rewrite rules be in a .htaccess file or
in the httpd.conf?

greetings,

Duikboot


manoj.agarwal.in@gmail.com wrote:
> Hi
>
> I want to do some hash on the HTTP_COOKIE string which gives me a value
> between 1 to 1000. For this I have written a PERL script. Now I want to
> call this PERL script in my rewrite.conf (rewrite rule file) file in
> apache. I am using RewriteMap for this but haven't succeeded. May be I
> haven't understood using rewritemap well.
> So my question is:
>
> a. Can I reset my HTTP_COOKIE value in the rewrite.conf file?
> b. Would calling a PERL script be a good idea for this or is there any
> other way around?
> c. Can I write the logic of hashing within my conf file?
>
>
> My conf file looks like:
>
> RewriteMap cookie1 prg:/home/y/share/htdocs/cookie1.pl
> RewriteRule ^/(index.html)?$ ${bcookie:$1} [L,PT]
>
> Am I doing something wrong in this?
>
> rgds
> Manoj
>

Robert Ionescu

2006-02-21, 5:56 pm

Duikboot wrote:
> I am not sure, but shouldn't the rewrite rules be in a .htaccess file or
> in the httpd.conf?


httpd.conf should be always preferred for a better performance because
the RegEx is only compiled once at startup and not per each processing
of the .htaccess file. A RewriteMap cannot be defined in per-dir
context, so the directive must be placed in per-server context (main
server config section or virtualhost).

-> Avoid .htaccess files, if possible.

--
Robert
Robert Ionescu

2006-02-21, 5:56 pm

manoj.agarwal.in@gmail.com wrote:
> a. Can I reset my HTTP_COOKIE value in the rewrite.conf file?


Some environmental variables (i.e. document_root) cannot be changed via
the E-Flag or mod_setenv(if).

The RewriteMap only returns a value which is being insert here in the
substitution. I don't think that you can manipulate ENVs from the prg
lookup script.

The manual states this:
| For each map-function lookup it will receive the key to lookup as a
| newline-terminated string on stdin. It then has to give back the
| looked-up value as a newline-terminated string on stdout

Three options I can think of:
-> You're writing an other int function in mod_rewrite.c from where you
should have access to all apache internals

-> You can try to use the E-flag to set a ENV but as I said, i don't
think that you can override this variable here like

# escape literal periods
RewriteRule ^/(index\.html)?$ - [E=HTTP_COOKIE:${bcookie:$1}]

or if you can't place a map lookup within the E-flag (it's not
documented), I'd use something like

RewriteCond ${bcookie:$1} ^(.*)
RewriteRule ^/(index\.html)?$ - [E=HTTP_COOKIE:%1]

-> You're rewriting to some cgi-script which changes the variables and
then execute a program which returns some output like
exec /usr/bin/php ...somepath...

The difference here is you're in the last step of the processing
(content handler).

> Now I want to call this PERL script in my rewrite.conf (rewrite rule
> file) file in apache.


Make sure that the rules are being executed, i.e. if you're using
virtualhosts, you must place the rules there, or you use
| RewriteEngine on
| RewriteOptions inherit

in your <virtualhost> to include/execute the rules from the main server
config section.

In order to check if the rules are being processed, I'd use a RewriteLog.

--
Robert
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com