homepage Welcome to WebmasterWorld Guest from 54.163.84.199
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewrite different static url's to a common-txt.html
but cgi delivers different colors
maggi




msg:1497098
 1:23 pm on Aug 1, 2003 (gmt 0)

I use iframes with give-away content in order to get links from the webmasters having implemented the iframe.
The page has always the same text content,
but the static link differ due to color information.
So I see a risk to be penalized by Google for duplicated content.
I would like to let the webmasters adopt the iframe page to their design - text (000000) and backgroundcolor (FFFFFF), therefore the static url is as:
content1_000000_FFFFFF (here shown with content1_000000).
- so there could be a lot of combinations all with the same content.

My mod_rewrite aproach is:
1 and 2: Rewrite to [mydomain...]
3: Compose the cgi string based on Environmental variables

1.RewriteCond %{REQUEST_FILENAME} ^\/([^_]+)_([^_]+)
2.RewriteRule ^.*$ [mydomain...] [env=adr1:%1,env=adr2:%2]
3.RewriteRule ^.*$ /cgi-bin/to.cgi?id=%{env=adr1}&id2=%{adr2} [L]

Line 2 is working, the log shows: ... setting env variable 'adr2' to '000000'
but the values are not inserted into line 3 - in none of the both syntax forms I tried.

How may I insert {env=adr1} in line 3?

Thanks, Maggi

 

jdMorgan




msg:1497099
 5:18 pm on Aug 1, 2003 (gmt 0)

maggi,

If you don't need those env vars for later use, you can simplify this to:

RewriteCond %{REQUEST_FILENAME} ^/([^_]+)_([^_]+)
RewriteRule .* /mycommonpage/cgi-bin/to.cgi?id=%1&id2=%2 [L]

Jim

maggi




msg:1497100
 10:27 am on Aug 4, 2003 (gmt 0)

I need the environment variables for later use in the template.
When not forcing a redirect, the ENV are passed and I can see them in a SSI page with <!--#printenv --> and in the template called by the perl script.
RewriteRule ^\/2/([^_]+)_([^_]+)\.html$ /2/$1.html [E=AAAA:$1,E=BBBB:$2,L]
The problem is, that when I include a Redirect=301 in the RewriteRule, than the environment variables are _not_ passed.
That might be a reason from the second (redirected) call by the browser?
Is there a way to store the environment variables inside mod_rewrite from the status like in RewriteCond to the?
When using
RewriteCond %{REQUEST_FILENAME} ^\/2/([^_]+)_([^_]+)\.html
RewriteRule ^.*$ RewriteCond %{REQUEST_FILENAME} ^\/2/([^_]+)_([^_]+)\.html
RewriteRule ^.*$ /2/%1.html [E=AAAA:%1,E=BBBB:%2,R=301,L]
I get the the page mydomain/2/%1.html with the value vor %1 as existent in the calling url.,
but not the environment variables analysed in the RewriteCond.
I found a note in
[forums.devshed.com...]
"Ok, first of all, there is NO way to pass environment variables through an external URL-to-URL redirect. The only way is QUERY_STRING parameters."
In the case above it is a not a external redirect (and the same result ocures when using a url-to-file redirect).
The question is:
How may I maintain the environment variables and pass them to the redirected page?
Thanks, Maggi

jdMorgan




msg:1497101
 4:18 pm on Aug 4, 2003 (gmt 0)

maggi,
You wrote:
I need the environment variables for later use in the template.
When not forcing a redirect, the ENV are passed and I can see them in a SSI page with <!--#printenv --> and in the template called by the perl script.
RewriteRule ^\/2/([^_]+)_([^_]+)\.html$ /2/$1.html [E=AAAA:$1,E=BBBB:$2,L]
The problem is, that when I include a Redirect=301 in the RewriteRule, than the environment variables are _not_ passed.
That might be a reason from the second (redirected) call by the browser?
Is there a way to store the environment variables inside mod_rewrite from the status like in RewriteCond to the?

No, there's no way to do this inside the server. The reason is that each HTTP request is a new "session" as far as the server is concerned. Environment variables are associated with each request, as they must be, to keep, for example, simultaneous requests from different users from getting mixed up. Therefore, the server has no "memory" of user "sessions" unless you use cookies or put session ID information into the URL itself. HTTP is a "stateless" protocol, and each request is unique - standing alone - with no internal association with any other previous or subsequent requests. (Boy, I hope that is clear - I don't know how to say it better!)

So, the answer, as you quoted from devshed below, is to attach the info you need to pass through to the next HTTP request to the redirected URL in the form of a query string, i.e., [yourdomain.com...] or perhaps to pass this info in the form of subdomains (http://%1.%2.mydomain.com/%1.html), or to use cookies.

You may wish to re-think your whole approach based on this, and I don't claim to know or understand the reasons you need to do this, so I won't elaborate more. But I hear the shades of Occam and Einstein, saying, "Given two choices of equal merit, the simplest one is usually best," and, "Make everything as simple as possible, but no simpler." And Ben Franklin chiming in with, "Eschew obfuscation."

When using
RewriteCond %{REQUEST_FILENAME} ^\/2/([^_]+)_([^_]+)\.html
RewriteRule ^.*$ RewriteCond %{REQUEST_FILENAME} ^\/2/([^_]+)_([^_]+)\.html
RewriteRule ^.*$ /2/%1.html [E=AAAA:%1,E=BBBB:%2,R=301,L]
I get the the page mydomain/2/%1.html with the value vor %1 as existent in the calling url.,
but not the environment variables analysed in the RewriteCond.
I found a note in
[forums.devshed.com...]
"Ok, first of all, there is NO way to pass environment variables through an external URL-to-URL redirect. The only way is QUERY_STRING parameters."
In the case above it is a not a external redirect (and the same result ocures when using a url-to-file redirect).

I may be confused, but [R=301] is an external redirect, sending a response back to the client with instructions to re-issue the client request using the included (new) URL. As such, the server "forgets" the current environment variables after the 301 response is sent; the current HTTP request has been satisfied with the 301 response and is therefore terminated and "forgotten."
Note that the syntax of the RewriteRule about is not quite right; use either:
RewriteRule ^.*$ /2/%1.html [E=AAAA:%1,E=BBBB:%2,L]
-or-
RewriteRule ^.*$ [yourdomain.com...] [R=301,L]
(passing the vars as a query string for the external redirect)
The question is:
How may I maintain the environment variables and pass them to the redirected page?

I hope I answered the question - This one made my brain hurt!

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved