Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Server Operation

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 18th January 2013, 08:22
flyingmg flyingmg is offline
Junior Member
 
Join Date: Jan 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using cookie content as RewriteRule variable in Apache ReverseProxy

Hi,

I have two questions regarding the use of cookies in Apache RewriteRules:

I want to build a specific URL depending on the content of a cookie.

This is how I get my cookie:
Code:
RewriteCond %{HTTP:Cookie} !aCookie=set
	RewriteCond %{REQUEST_URI} ^/(.*)/mail/
	RewriteRule /(.*)/mail/ - [CO=ServerName:$1:.acme.com,CO=aCookie:set:.acme.com]
This works and I get the server name depending on the URL pattern in my cookie ServerName. This cookie is then used during the whole session.

Now I'd like to:
1. check wether the cookie is set (without knowing its content). I was not able to achieve that until now and actually set a second cookie (aCookie in my example above) and check for its content as a first condition. Does the first line of my example below achieve that? I couldn't verify that until now...

2. use the content of the cookie ServerName to build subsequent URLs
I thought, that I could build something like:

Code:
	RewriteCond %{HTTP:Cookie} !ServerName=		# does this check for the existence of the cookie????
	RewriteCond %{REQUEST_URI} ^/
	RewriteRule /(.*) http://<Content of saved cookie>.acme.com/$1 [P]
But could not find any hint on how to achieve that until now.

Any hints would be greatly appreciated.

Thx, Marc

My question is related to Apache 2.4 as reverse proxy on ubuntu 12.04.1
Reply With Quote
Sponsored Links
  #2  
Old 24th January 2013, 11:11
flyingmg flyingmg is offline
Junior Member
 
Join Date: Jan 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question

Meanwhile I could figure out how to access to the content of the cookie. But I am still stuck with a RewriteCond that should just check wether the cookie is set or not, independnatly from its content. The content should be used as a result of the condition being fullfilled and putting it into %1.
After some google search, I found several example how to check for some content and changed it, so that I thought it should match my needs. Unfortunatly, it does not work as desired until now.
My rewrite condition and rule looks actually like that:
Code:
RewriteCond %{HTTP_COOKIE} ServerName=(.*)[-,;]?
RewriteCond %{REQUEST_URI} ^/
RewriteRule /(.*) http://%1.acme.com/$1 [P]
How should my Rewritecond looks like, so that it checks that the cookie is set to anything and return its content back?
Any hint would be greatly apreciated.
Thx, M.
Reply With Quote
  #3  
Old 7th February 2013, 12:58
flyingmg flyingmg is offline
Junior Member
 
Join Date: Jan 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
 
Thumbs up SOLVED: Using cookie content as RewriteRule variable in Apache ReverseProxy

Just to close this thread and tag it as solved, if somebody is looking for a solution for a similar problem.
Here is the solution:

If have a cookie named ServerName, I want to check for its availability and use its content for building a URL:

Code:
RewriteCond %{REQUEST_URI} ^/
RewriteCond %{HTTP_COOKIE} ^.*ServerName=([^;]+)
RewriteRule /(.*) http://%1.acme.com/$1 [P]
does the trick.
Hope this helps somebody...
Reply With Quote
Reply

Bookmarks

Tags
apache, apache 2.4, reverse proxy, ubuntu 12.04 lts

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sessions not being saved gavimobile General 6 15th January 2012 15:05
Apache hangs without traffic Thesee General 21 27th September 2011 23:43
trubble installing elgg cruz Technical 9 20th August 2009 15:48
Get the rid of it :( htaccess jvdkdesign Installation/Configuration 19 23rd June 2009 09:55
Unable to install ISPConfig bdonecker Installation/Configuration 21 26th May 2009 08:20


All times are GMT +2. The time now is 10:07.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.