Forum Moderators: phranque

Message Too Old, No Replies

htaccess url rewrite not working if page is in cache

         

Scott_Witte

9:23 pm on Oct 5, 2010 (gmt 0)

10+ Year Member



I am trying to redirect a URL referral from a particular site to an alternate page but find that if the page originally requested is in the browser's cache it will display instead of my desired alternate. What am I doing wrong?

The relevant part of my .htaccess file:

RewriteEngine on

RewriteCond %{HTTP_REFERER} ^http://(www\.)?peiso.es/.*$ [NC]
# to avoid an "infinite" rewrite loop:
RewriteCond %{REQUEST_URI} !^/stolen.html$
RewriteRule ^(.*)$ /stolen.html [R,L]


If you care to see this in action the offending site is: [peiso.es ]. (Turn off the awful sound near the bottom of the page.) Click on the golfing photo in the upper left. You should get the warning page saying that the link was unauthorized.

Now go to the page they are trying to show: [tourdeforce360.com ]. You only need to open it so the html is in cache. Now try the link from peiso again and the hawaiian page shows up, not the redirected "stolen" page.

jdMorgan

2:59 am on Oct 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either live with the fact that the page has been cached and is therefore not being fetched from your server, or set the cache-control headers so that the page is un-cacheable or expires quickly, and accept the resulting increase in server resource usage. Apache mod_headers and mod_expires are the main client-cache-control mechanisms on Apache, but also see the "FileETag" directive.

Example construct:

# Enable mod_expires
ExpiresActive On
#
# Uncacheable pages
<FilesMatch "(test|401|403|404|410|500)\.html$">
FileETag None
ErrorHeader set Cache-Control "no-store"
ExpiresDefault A0
</FilesMatch>

Jim

Scott_Witte

7:53 pm on Oct 6, 2010 (gmt 0)

10+ Year Member



Thanks, Jim,

At least I know I'm not doing anything wrong after all. Best option for me is to leave it as is, then. It seems exceedingly unlikely that someone following a stolen link would already have the intended page in cache anyway. Relying on that is much better than making my content uncacheable.

jdMorgan

1:11 am on Oct 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the same is true for hot-linked images. Once they're cached they won't be fetched from your/our servers anyway, so no harm in leaving the image cacheable.

And if one tends to be the least bit vindictive, imagine the confusion of the "linking" Webmaster (in both cases here) who gets reports from his users that the link (or the hotlinked image) does not work. Then he goes to check, and he sees it working because he's got the target cached in his browser... But he keeps getting error reports from his users who *don't* have that target cached. Given that many Webmasters of the type who create unwanted links or hotlink images don't understand HTTP or caching, this in itself can be considered "justice." :)

Jim

Scott_Witte

3:05 am on Oct 7, 2010 (gmt 0)

10+ Year Member



Sweat justice ;)