Forum Moderators: phranque
So I'm running Apache 1.3 and I have to do the following in .htaccess (I have to do this at the Apache level)
1. Check Cookie "name=checkme" in .htaccess
A) IF Cookie Not Set then do the following:
1a. Set a Cookie using .htaccess - "checkme=1"
2a. Redirect to an Image - "showme1.jpg"
B) ELSE Cookie is Set
1b. Redirect to an Image - "showme2.jpg"
I hope this makes sense. This would be easy in php for me to do but unfortunately I need to do this in .htaccess.
Any suggestions would be greatly appreciated!
OK IF the above is possible then this Step:
"2a. Redirect to an Image - "showme1.jpg""
I basically want to randomize the redirect so that:
50% of the time I redirect to "showme1.jpg"
* and *
50% of the time I redirect to "showme1.jpg"
Again all of this in the .htaccess file.
You can, however, use mod_headers directives within a <FilesMatch> container in .htaccess to set a cookie based upon a file load (any file or a specific file -- for example, your showme1.jpg image).
That cookie *can* be checked in Apache 1.3.x or 2.x .htaccess using a mod_rewrite RewriteCond.
If you are trying to flip back and forth between two images, then part of your logic is missing -- You'll need to clear the cookie when the second image is loaded. And if this has to work every time, then you must also mark both images as non-cacheable (also using mod_headers, plus mod_expires).
So, that's three bits of Apache module documentation, plus the Apache Core doc to get started with... :)
Jim
Basically what I did is I checked for the cookie in the .htaccess file. If it was set then I would show the image. Otherwise I used a php script and redirect to set the cookie and show the second image.
jdMorgan - I noticed when I was purely using .htaccess to set a cookie using this:
<FilesMatch "^test2\.html$">
Header set set-cookie: "mobile; path=/; domain=MYDOMAIN.com"
</FilesMatch>
and then doing a rewrite rule after the <FilesMatch> to redirect... the cookie never got set. However when I just do the <FilesMatch> without the redirect the cookie gets set....do you know why this is so?
but, btw, why don't you just check the referer? You could just say "if the referer isn't empty and it isn't from my site, then show them some picture telling them to go to my website and shun the hotlinker"
It's critical to understand that directives in your .htaccess file *are not* executed in the order you type them -- You should not view .htaccess code as a sequentially-executed "program." Directives in .htaccess are executed on a per-module basis, as determined by the server configuration. That is, all directives handled by the first module are executed, followed by all directives from the second module, etc. So the order in which you put your code only affects the relative order of execution of directives handled by the same module.Module execution order on Apache 1.x is determined by the reverse LoadModule order in httpd.conf. It is determined by an internal priority scheme on Apache 2.x.
Jim