[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1197
  • Last Modified:

htaccess redirect based off referer __500 pts__

for this example lets say my site is applesauce.com

I want anyone who is coming from these sites:
cookies.com
waffles.com
bacon.com
pancakes.com

to see applesauce.net instead of applesauce.com

but if someone from cookies.com( and others ) wants to see applesauce.com/store/home.php i want to let them

is this doable in htaccess?
0
Defter
Asked:
Defter
  • 8
  • 7
  • 6
  • +1
1 Solution
 
LeeKowalkowskiCommented:
Try the example on this page: http://dmr.ath.cx/notes/rewrite.html

--
Lee
0
 
DefterAuthor Commented:
how would you suggest that work?
0
 
ahoffmannCommented:
RewriteCond %{SERVER_NAME} ^(cookies|waffles|bacon|pancake)|.com$
RewriteCond %{REQUEST_URI} !^/store/home.php$
RewriteRule (.*) http://applesauce.com/$1

# Note: this is the lazy aproach according your lazy description, I guess you meant something else ...
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
HackneyCabCommented:
ahoffman, do you mean the first line to be:

RewriteCond %{HTTP_REFERER} ^(www\.)?(cookies|waffles|bacon|pancakes)\.com$

and the third line to be:

RewriteRule (.*) http://applesauce.net/$1
0
 
ahoffmannCommented:
no (I'd never post a suggestion to use the referrer 'cause it's useless:)
0
 
LeeKowalkowskiCommented:
Just because it's not guaranteed to be present doesn't mean you can't make use of it if it is.

I hear it's very useful to stop authors of other pages hijacking your bandwidth by referring to images directly from your server.

--
Lee
0
 
ahoffmannCommented:
> .. not guaranteed to be present doesn't mean you can't make use of it ..
hmm, you're right, but I said That "I won't suggest" it ;-)

> I hear it's very useful ..
.. just for those authors of other pages who are to dumb to fake the referrer ..
0
 
LeeKowalkowskiCommented:
> .. just for those authors of other pages who are to[o] dumb to fake the referrer ..

Not sure what this means.  Referer comes from the client and cannot be controlled server-side or by authors.  It can be switched off by users of Opera though, but not faked.

It can only be faked by developers making server-side requests in which case they're definitely not doing it to save their own bandwidth.

I don't see how RewriteCond %{SERVER_NAME} ^(cookies|waffles|bacon|pancake)|.com$ would ever find a match when the request is being sent to applesauce.com.

The question was if the request is for applesauce.com and the referer is one of (cookies/waffles/bacon/pancakes.com), go to applesauce.net, except for requests for /store/home.php.

--
Lee

0
 
ahoffmannCommented:
> .. It can only be faked by developers making server-side requests ..
I can fake the referer to whatever you want (without knowing anything on server-side except HTTP:)

> I don't see how RewriteCond %{SERVER_NAME} ..
I already explained that it was a *lazy* suggestion, lets wait 'til the questioner responds to that and explains what (s)he realy wants.

> The question was .. and the referer is one of ..
no,
or where do you read that?
How about if applesauce.com and cookies.com are the same IP, or at least virtual (IP-based) hosts in the same web server?
0
 
LeeKowalkowskiCommented:
> no, or where do you read that?

Easy, the question says "coming from", not "going to".  That's what referer means.

--
Lee
0
 
DefterAuthor Commented:
It looks like lee is on the right track, others have told me referer as well
0
 
DefterAuthor Commented:
would you recommend using htaccess or php?
0
 
LeeKowalkowskiCommented:
.htaccess is definitely the place to put the logic you describe.  You don't want to be cluttering your beautiful PHP code with server-specific logic if you can avoid it.

I don't really have the setup you describe to play with though, so I can't test it, besides I do very little mod_rewrite personally.  

RewriteCond %{HTTP_REFERER} ^https?://(www\.)?(cookies|waffles|bacon|pancakes)\.com
RewriteCond %{REQUEST_URI} !^/store/home.php
RewriteRule (.*) http://applesauce.net/$1

--
Lee
0
 
DefterAuthor Commented:
will try that and get back to you, thanks.
0
 
ahoffmannCommented:
>  That's what referer means.
agreed, but that's not what was described in the question :)

Anyway, the author now explained better ...
Defter, is a solution using HTTP_REFERER suffucient for you, even we know that it could be missing (due to various reasons) and/or set to anything I want (even the value you're expecting)?
0
 
DefterAuthor Commented:
user browses to sites A, therein is a link to Site B, when directed to Site B from Site A, Site B reads that they're coming from Site A, and pushes them onto Site C.

Is that clear enough or ??
0
 
ahoffmannCommented:
yes that's clear for me, but you still seem to forget:
how does it work if the referer is missing (due to whatever reason)?
0
 
DefterAuthor Commented:
if the referer is missing it just acts as if there isnt one?
0
 
LeeKowalkowskiCommented:
Yes, just like when a user goes directly to applesauce.com.

--
Lee
0
 
DefterAuthor Commented:
thats what i thought, thanks guys
0
 
ahoffmannCommented:
> but if someone from cookies.com( and others ) wants to see applesauce.com/store/home.php i want to let them
so we agree that following is ok:

1. new browser hence no refer(r)er
2. spoof referer like:
  Referer: http://cookie.com/
3. http://applesource.com/store/home.php
4. bingo, got it.
0
 
DefterAuthor Commented:
ure right that will work, and im fine with that...
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 8
  • 7
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now