Forum Moderators: phranque

Message Too Old, No Replies

Using mod rewrite to alter headers

Using mod_rewrite to alter headers

         

Zolthan

9:58 pm on Nov 28, 2007 (gmt 0)

10+ Year Member



I'm trying to use mod_rewrite to give different headers to different IP ranges. At the moment I'm having to maintain 2 copies of the same data with different htaccess files and I want to combine the info.

The htaccess file starts of nice and easy:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^[IP Address here]$

But I can't figure out how to get the additional headers to work. I need these two lines in the htaccess file for the specific address:
Header unset Cache-control:
Header append Cache-control: "no-transform"

Is there a way I can use rewrite to call a 2nd htaccess type file or add in those specific lines. Or am I going about this all the wrong way?

Thanks.

phranque

10:20 pm on Nov 28, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], Zolthan!

"Header" is not a mod_rewrite directive.
you need to have mod_headers [httpd.apache.org] installed for the "Header" directive to work.

Zolthan

12:19 am on Nov 29, 2007 (gmt 0)

10+ Year Member



Thanks for the answer - I though that would be the case - but thought I'd ask anyway. I guess you can't call in a 2nd htaccess file using mod_rewrite either.

I'll keep working on it.

jdMorgan

12:40 am on Nov 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This may not be the best way to do this, but it works:

Use a RewriteCond to test the IP address, and internally rewrite the request to a second copy of the file if it is requested by that IP address.

Then put your Header set directive inside a <FilesMatch> container to change the cache-control header when the second copy of the file is requested.

Jim