Forum Moderators: phranque

Message Too Old, No Replies

configuring httpd.conf for cookie free web folder

         

tom12c

3:26 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



I'm trying to determine if this is possible or not.

I have a folder for site images on my site. Using ySlow, I am getting an F for a cookie-free domain.

Lots of my images have cookies attached to them I would guess.

Is there a way in the apache configuration to exclude cookies from being used in a specific web folder?

Thanks in advance! If you have any questions, please feel free to ask.

Tom

swa66

5:31 pm on Jun 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd simply use a different hostname on a virtual host that does not use cookies at all. e.g. img.example.com and make sure you set your cookies only to be sent to where they are needed.
The tricky bit is that once you set a cookie the client will send it to you on every request no matter what.

tom12c

5:42 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



As tempting as it would be to use a completely new virtual server for only the images (might be the only way, not sure yet, that would also mean changing the link location for all the images being used on the site (and there are a lot!). trying to avoid that if i can.

jdMorgan

10:54 pm on Jun 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The answer depends on another question: How are your cookies set?

It does not make sense for ySlow to 'blame' you because the client sends the cookie to your domain with every HTTP request. However if your server is trying to set a cookie in response to every HTTP request, then that might deserve an "F" grade.

Let's be clear on what a cookie is: The server sends a Set-Cookie HTTP response header to the client that says, "Whenever you send me an HTTP request, send this data back to me with an HTTP "Cookie" header."

Usually a cookie is set once, or set when the user changes his preferences, or set when the user changes pages (tracking cookie). Cookies also have "realms" which are essentially "subdirectory branches." The problem is that you can easily set what realm (subdirectory-path) the cookie *does* apply to, but it's not possible to specify what realm it *does not* apply to.

Have you tried looking at the client/server cookie interaction using the Live HTTP Headers add-on for Firefox/Mozilla? -- That might clarify the situation a bit.

Jim

tom12c

1:40 pm on Jul 7, 2009 (gmt 0)

10+ Year Member



What you said made me think a lot.

At this moment, I'm trying to figure out if there is a way to do mod_rewrite on on images links within pages.

For example

I have a webpage at http://www.example.com/sub-dir/index.php

This page contains images at http://www.example.com/_images/

Ie. http://www.example.com/_images/my-image.jpg

I created a whole new virtual server at /var/www/images/ and a soft link

ln -s /var/www/images /var/www/html/_images

(Any images referenced from /var/www/html/_images will hopefully point to [images.example.com...]

ie. http://www.example.com/_images/my-image.jpg to [images.example.com...]

In my htaccess file I have so far

RewriteEngine on
#RewriteLog /var/log/httpd/mod_rewrite.log
#RewriteLogLevel 3
RewriteBase "/_images"
#RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^_images/$1 [images.example.com...] [R]

Don't quite have it yet.

Is what I'm trying to do even possible? Am I using the right approach? Or is there a better approach?

Please feel free to let me know. Thanks!

[edited by: jdMorgan at 4:15 pm (utc) on July 7, 2009]
[edit reason] example.com [/edit]

jdMorgan

4:14 pm on Jul 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Domains/hostnames are meaningless 'inside' the file structure of a site. Therefore, if you have a (correct and working) symlink from the filespace referenced by "www.example.com/_images" to the filespace referenced by "images.example.com/" there should be no need for any rewriting or redirecting.

It is very helpful to solving these problems to remember that URLs are used on the Web, and filepaths are used inside the server, and that the two are not "equivalent" or "similar" in any way, but only "associated" by the action of the server itself. So don't confuse these two "object location domains," and keep in mind that all you need to do is to make shared image *files* appear to be duplicated in the filespace used by "www.example.com".

If however, you want the images fetched using a different domain (e.g. to speed the site up a little), then the answer is simple (if not what you want to hear): change the links on your pages to point to the proper new image URLs. mod_rewrite cannot be used to 'fix' URLs, it can only be used to change the requested-URL-to-filepath mapping. Trying to use it to 'change URLs' will result in doubling the number of requests to your server, slowing down your site, and polluting your log files and stats, because every image request will be redirected and result in a second HTTP request -- quite the opposite result from that usually desired...

Jim