Myreader.co.uk  
uk news, chat and community
   home   |   control panel login   |   archive   |  
 
net
net
news.announce
news.config
news.management
news.moderation
providers
providers.aaisp
web.authoring
  
 
date: Thu, 05 Jun 2008 18:41:10 +0100,    group: uk.net.web.authoring        back       
Redirect based on referrer   
Hi

An easy one for someone who understands .htaccess syntax.

To stop external links going to a page deep within my site and instead to
take them to the home page, I want to redirect all page requests that have
either blank or referrer information other than from within the site
itself. I don't want to use Javascript and think that this can be done in
.htaccess  using something along the lines of:

	RewriteEngine on
	RewriteCond %{HTTP_REFERER} ^http://www\.somewhere\.com [NC]
	RewriteRule \.png http://www.somewhere.com/somepage.htm [R]

but with the RewriteCond negated so that any referrer (including none) gets
redirected to the http://www.somewhere.com/somepage.htm URL.

How do I negate the RewriteCond statement and make in include no referrer
(or is this one and the same)?

TIA

Richard
See http://www.caravanningnow.co.uk where my caravan's for sale.
-- 
Happy Birthday!! (well, I'll be right one day).
date: Thu, 05 Jun 2008 18:41:10 +0100   author:   Richard Cole lid

Re: Redirect based on referrer   
On Thu, 5 Jun 2008, Richard Cole wrote:

> How do I negate the RewriteCond statement

With an exclamation mark  !  as prefix.

http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

-- 
In memoriam Alan J. Flavell
http://groups.google.com/groups/search?q=author:Alan.J.Flavell
date: Fri, 6 Jun 2008 16:11:23 +0200   author:   Andreas Prilop

Re: Redirect based on referrer   
On Fri, 6 Jun 2008 16:11:23 +0200, Andreas Prilop
 wrote:

>On Thu, 5 Jun 2008, Richard Cole wrote:
>
>> How do I negate the RewriteCond statement
>
>With an exclamation mark  !  as prefix.

Andreas

So
	RewriteEngine on
	RewriteCond %{HTTP_REFERER} !^http://www\.somewhere\.com [NC]
	RewriteRule \.png http://www.somewhere.com/somepage.htm [R]

is this the correct syntax, the Apache documents assume more than a very
basic knowledge of C type condition tests.

Thanks

The problem is that the site is live and gets a lot of visitors, so I can't
afford for it to be down while testing the syntax online.

Richard
See http://www.caravanningnow.co.uk where my caravan's for sale.
-- 
Candidates for the Tyrantship were elected by the placing of black or
white balls in various urns, thus giving rise to a well-known comment
about politics. - 'Small Gods' by Terry Pratchett
date: Fri, 06 Jun 2008 21:05:44 +0100   author:   Richard Cole lid

Re: Redirect based on referrer   
In message , Richard Cole 
<ispcrco@hotmail.com.invalid> writes
>The problem is that the site is live and gets a lot of visitors, so I can't
>afford for it to be down while testing the syntax online.

If you don't have another hosting account you could use to test it 
(ideally on the same server) then it might be worth installing Apache on 
your PC - easily done with XAMPP

http://www.apachefriends.org/en/xampp.html

to test it locally before deploying it.
-- 
Dominic Sexton
date: Sat, 7 Jun 2008 11:34:30 +0100   author:   Dominic Sexton {da-sep03}@dscs.demon.co.uk

Re: Redirect based on referrer   
On Sat, 7 Jun 2008 11:34:30 +0100, Dominic Sexton
<{da-sep03}@dscs.demon.co.uk> wrote:

>In message , Richard Cole 
><ispcrco@hotmail.com.invalid> writes
>>The problem is that the site is live and gets a lot of visitors, so I can't
>>afford for it to be down while testing the syntax online.
>
>If you don't have another hosting account you could use to test it 
>(ideally on the same server) then it might be worth installing Apache on 
>your PC - easily done with XAMPP
>
>http://www.apachefriends.org/en/xampp.html
>
>to test it locally before deploying it.
Dominic

Thanks. 

I've installed xampp on a virtual Ubuntu box and I'm currently trying to
configure it (Unix is not my strong point!).

Richard
See http://www.caravanningnow.co.uk where my caravan's for sale.
-- 
'And, er, what are you, Miss Susan?' 'Me? I'm . . . a schoolteacher.'
She followed his gaze to the wrench that she still held in her hand,
and shrugged. 'It can get pretty rough at break time, can it?' said
Lobsang.  - The Thief of Time by Terry Pratchett.
date: Sat, 07 Jun 2008 21:47:27 +0100   author:   Richard Cole lid

Re: Redirect based on referrer   
On Fri, 6 Jun 2008, Richard Cole wrote:

> The problem is that the site is live and gets a lot of visitors, so I can't
> afford for it to be down while testing the syntax online.

Testing is very easy: Create a folder

   http://www.example.com/myhiddenfolder/

which only *you* know, and make your tests in "myhiddenfolder".

BTW:
Use  http://www.example.com/
     http://www.example.net/
     http://www.example.org/
when you need dummy addresses.

-- 
In memoriam Alan J. Flavell
http://groups.google.com/groups/search?q=author:Alan.J.Flavell
date: Mon, 9 Jun 2008 17:49:18 +0200   author:   Andreas Prilop

Re: Redirect based on referrer   
On Mon, 9 Jun 2008 17:49:18 +0200, Andreas Prilop
 wrote:

>On Fri, 6 Jun 2008, Richard Cole wrote:
>
>> The problem is that the site is live and gets a lot of visitors, so I can't
>> afford for it to be down while testing the syntax online.
>
>Testing is very easy: Create a folder
>
>   http://www.example.com/myhiddenfolder/
>
>which only *you* know, and make your tests in "myhiddenfolder".
>
>BTW:
>Use  http://www.example.com/
>     http://www.example.net/
>     http://www.example.org/
>when you need dummy addresses.
Andreas

This is fine for testing new pages and javascript tweaks, but I need to
test a revised .htaccess.

I do have a 'spare' sub-domain name that currently just points to top level
site, so if I pointed this so that http://www.spare-example.con pointed to
http://www.example.com/myhiddenfolder and I put the test .htaccess in
http://www.example.com/myhiddenfolder, would this work or would Apache only
use the .htaccess in http://www.example.com/ ?

Thanks

Richard
See http://www.caravanningnow.co.uk where my caravan's for sale.
-- 
Thunder rolled . . . It rolled a six. - 'Guards! Guards!' by Terry
Pratchett
date: Mon, 09 Jun 2008 19:38:50 +0100   author:   Richard Cole lid

Re: Redirect based on referrer   
Richard Cole <ispcrco@hotmail.com.invalid> writes:

> On Mon, 9 Jun 2008 17:49:18 +0200, Andreas Prilop
>  wrote:
>
>>On Fri, 6 Jun 2008, Richard Cole wrote:
>>
>>> The problem is that the site is live and gets a lot of visitors, so I can't
>>> afford for it to be down while testing the syntax online.
>>
>>Testing is very easy: Create a folder
>>
>>   http://www.example.com/myhiddenfolder/
>>
>>which only *you* know, and make your tests in "myhiddenfolder".
>>
>>BTW:
>>Use  http://www.example.com/
>>     http://www.example.net/
>>     http://www.example.org/
>>when you need dummy addresses.
> Andreas
>
> This is fine for testing new pages and javascript tweaks, but I need to
> test a revised .htaccess.

That won't have passed him by.  Unless you have a very odd
configuration, .htaccess affects the folder it is put it (and, where
it makes sense, those below).

> I do have a 'spare' sub-domain name that currently just points to top level
> site, so if I pointed this so that http://www.spare-example.con pointed to
> http://www.example.com/myhiddenfolder and I put the test .htaccess in
> http://www.example.com/myhiddenfolder, would this work

Yes, but it would also work without re-pointing the spare domain.
Accesses to http://www.example.com/xyz would be unaffected and
accesses to http://www.example.com/myhiddenfolder/pqr would be based
on the referer.

> or would Apache only
> use the .htaccess in http://www.example.com/ ?

-- 
Ben.
date: Tue, 10 Jun 2008 14:46:07 +0100   author:   Ben Bacarisse

Re: Redirect based on referrer   
On Mon, 9 Jun 2008, Richard Cole wrote:

> I do have a 'spare' sub-domain name that currently just points to top level
> site, so if I pointed this so that http://www.spare-example.con pointed to
> http://www.example.com/myhiddenfolder and I put the test .htaccess in
> http://www.example.com/myhiddenfolder, would this work or would Apache only
> use the .htaccess in http://www.example.com/ ?

 http://www.example.com/.htaccess
applies to  www.example.com  as a whole,
which includes  www.example.com/myhiddenfolder/ .

 http://www.example.com/myhiddenfolder/.htaccess
applies to  www.example.com/myhiddenfolder/  only -
but it overrides any settings in  www.example.com/.htaccess .

-- 
In memoriam Alan J. Flavell
http://groups.google.com/groups/search?q=author:Alan.J.Flavell
date: Tue, 10 Jun 2008 17:34:07 +0200   author:   Andreas Prilop

Re: Redirect based on referrer   
On Tue, 10 Jun 2008 17:34:07 +0200, Andreas Prilop
 wrote:

>On Mon, 9 Jun 2008, Richard Cole wrote:
>
>> I do have a 'spare' sub-domain name that currently just points to top level
>> site, so if I pointed this so that http://www.spare-example.con pointed to
>> http://www.example.com/myhiddenfolder and I put the test .htaccess in
>> http://www.example.com/myhiddenfolder, would this work or would Apache only
>> use the .htaccess in http://www.example.com/ ?
>
> http://www.example.com/.htaccess
>applies to  www.example.com  as a whole,
>which includes  www.example.com/myhiddenfolder/ .
>
> http://www.example.com/myhiddenfolder/.htaccess
>applies to  www.example.com/myhiddenfolder/  only -
>but it overrides any settings in  www.example.com/.htaccess .

Andreas & Ben

Thanks. I've changed the forwarding of my 'spare' domain to point to a test
area (with a modified style sheet so I can check the forwarding is set
correctly) then I can have a hack at the .htaccess.

Thanks to you both and to Dominic for your help.

Richard
See http://www.caravanningnow.co.uk where my caravan's for sale.
-- 
I am always exact and precise (more or less).
date: Tue, 10 Jun 2008 18:36:47 +0100   author:   Richard Cole lid

Google
 
Web myreader.co.uk


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us