• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Apache mod_rewrite CGI Variables in ColdFusion

New Here ,
Nov 05, 2009 Nov 05, 2009

Copy link to clipboard

Copied

I have an environment that consists of Apache 2.2.8 and ColdFusion 8 running on Solaris 10.

I am attempting to pass a CGI variable to ColdFusion as part of an Apache Rewrite rule, however I am not able to do so.

The Rewrite rule set exists as follows:

RewriteCond %{SSL:SSL_PROTOCOL} ^TLSv1$
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteRule ^.*$ %{HTTP_REFERER}?result=pass [L,R,E=HTTP_MYVAR:rw]

The rule set works with the exception of the availability of the CGI variable HTTP_MYVAR within the ColdFusion CGI scope.

I am testing for the existance of the variable within ColdFusion as follows:

<cfif (structkeyexists(cgi, 'CGI.HTTP_MYVAR'))>
   CGI.HTTP_MYVAR exists as:<cfoutput>#CGI.HTTP_MYVAR#</cfoutput>
<cfelse>
   CGI.HTTP_MYVAR does not exist.
</cfif>

Does anyone have experience creating variables in an Apache Rewrite rule set and evaluating them in ColdFusion?

Thanks in advance for any assistance.

TOPICS
Advanced techniques

Views

3.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 06, 2009 Nov 06, 2009

Copy link to clipboard

Copied

Does anyone have experience creating variables in an Apache Rewrite rule set and evaluating them in ColdFusion?

I didn't until trying to investigate this issue for you, but do now.  So cheers for that! 🙂

Your problem, though, is nothing to do with MOD_REWRITE.  Have a look at this line of code:

<cfif (structkeyexists(cgi, 'CGI.HTTP_MYVAR'))>

Take a good close look at it...

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 18, 2010 Jan 18, 2010

Copy link to clipboard

Copied

Adam,

Thank you taking the time to look at this issue.

I have spent some time on this and I have not been successful in setting a variable in the Apache Rewrite rule and evaluating it within ColdFusion code.

Can you send me sample RewriteRule code and ColdFusion code if you have been successful in accomplishing this?

Thanks again.

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2010 Jan 18, 2010

Copy link to clipboard

Copied

Did you do what I suggested and have a good hard look at that CF code you posted?  And did you notice the mistake in it?

Your Apache settings are fine.  It's your CF code that's got a (reasonably obvious, once you look at it) mistake in it.

Think about the two parameters that structKeyExists() takes.  Have you got them right?  (hint: no).

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 18, 2010 Jan 18, 2010

Copy link to clipboard

Copied

structkeyexists() takes two parameters; structure and key.

My original code appeared as follows:

<cfif (structkeyexists(cgi, 'CGI.HTTP_MYVAR'))>

....

I have since modified it to:

<cfif (struckeyexists(cgi, 'HTTP_MYVAR'))>

....

and do not receive any different results.

I'm affraid I'm not seeing the error that you are suggesting exists.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2010 Jan 18, 2010

Copy link to clipboard

Copied

The thing that you fixed was the problem I was hinting at.

I'm afraid the computer I did the testing of this on is sitting in New Zealand, and I'm currently in the UK, so what I did is not to hand sorry.  I'll be back in NZ on the w/end though, so I'll dig it out then.

However my recollection is that I pretty much used your re-write code (simplified for a less specific situation), and it just worked.

If I find some time tomorrow, I'll try to replicate it again, and feed back.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 19, 2010 Jan 19, 2010

Copy link to clipboard

Copied

OK, as part of my work-avoidance for the day, I have replicated the work I did in NZ on my other laptop.

I put this in httpd.conf

Alias /junk C:/webroots/junk
<Directory "C:/webroots/junk">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
   
    RewriteEngine  on
    RewriteBase    /junk/
    RewriteRule (.*) $1 [E=MYCUSTOMVARIABLE:mycustomvalue]

</Directory>

And my test code is this:

<cfoutput>
CGI.MYCUSTOMVARIABLE = [#CGI.MYCUSTOMVARIABLE#]<br />
</cfoutput>

I restart Apache, run the template, and I get this:

CGI.MYCUSTOMVARIABLE = [mycustomvalue]

How does this differ from what you're doing?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2010 Jan 19, 2010

Copy link to clipboard

Copied

Thanks again for you help.

I modified my rewrite code as follows:

     #rewrite to a failure page if not TLSv1
     RewriteCond %{SSL:SSL_PROTOCOL} !^TLSv1$
     RewriteCond %{HTTP_REFERER} ^$ [NC]
     RewriteRule ^.*$ http://mysite.mydomain.com?tlsresult-fail [L,R,E=MYCUSTOMVARIABLE:mycustomvalue]

My ColdFusion code on the index page of the site includes:

         <cfdump var="#CGI#">
        <cfoutput>
                CGI.MYCUSTOMVARIABLE = [#CGI.MYCUSTOMVARIABLE#]<br />
         </cfoutput>          

The CGI variable CGI.MYCUSTOMVARIABLE does not appear in the CGI scope dump and the result of the <cfoutput> tag is:

CGI.MYCUSTOMVARIABLE=[]

I know that the RewriteRule is working for everything except the creation of the CGI variable.

Do you have any ideas what may be wrong?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 19, 2010 Jan 19, 2010

Copy link to clipboard

Copied

LATEST

<cfdump> will only dump out a subset of common CGI variables for some reason.  When quizzed, someone from Adobe suggested it's because to get any specific ones, it's a call to the web server or something, and there's overhead.  Sounded like a cop-out or the result of ill-thought-out code to me, but there you go.  This is also part of the "logic" as to why one can go isDefined("CGI.anythingCanGoHere") and it will always return true.  Stupid.

As for why it's not showing up when accessed directly, I presume it's because your conditions aren't being met.

Remove both of them and re-test, and work from there.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation