LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-26-2019, 04:36 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676
Blog Entries: 7

Rep: Reputation: 32
Help with .htaccess


Hi there
I do have quite an issue that I need solved by using .htaccess. The scenario is as follows :

User is on Facebook "or any other site" and to my site --> User is on my Site X and clicks on an affiliate button --> User Reaches my Site C

Affiliate Button This is setup in .htaccess - Redirect 301 www.siteX.com/affiliateButton -> https://www.siteC.com

What I need is the following



The .htaccess as it is shows

Redirect 301 www.siteX.com/affiliate -> https://www.siteC.com

I need it to show

Redirect 301 www.siteX.com/affiliate -> https://www.siteC.com?referrer=facebook.com

Any ideas ?
 
Old 08-26-2019, 06:33 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,611

Rep: Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802
Quote:
I need it to show

Redirect 301 www.siteX.com/affiliate -> https://www.siteC.com?referrer=facebook.com

Any ideas ?
I guess you're running apache given the .htaccess approach.
If that's the case, you can use mod_rewrite to append the referer at the resulting URL.

Regards
 
Old 08-26-2019, 08:30 AM   #3
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
Yes apache is in use, I did try a few combinations using Rewrite but non worked, can you provide me with any examples please ?
 
Old 08-26-2019, 12:37 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,611

Rep: Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802
Quote:
Originally Posted by ALInux View Post
Yes apache is in use, I did try a few combinations using Rewrite but non worked, can you provide me with any examples please ?
You can try something like:
Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} (.*)://(.*)/
RewriteRule affiliate https://www.siteC.com?referrer=%2 [L]
 
Old 08-28-2019, 05:00 PM   #5
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 137

Rep: Reputation: 66
Odd choice of matching protocol with (.*) - shouldn't it just be:
Code:
RewriteCond %{HTTP_REFERER} https?://(.*)/
(Along with %1 instead of %2 in the RewriteRule)

Last edited by boughtonp; 08-28-2019 at 05:06 PM.
 
Old 08-29-2019, 05:03 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,611

Rep: Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802Reputation: 1802
Quote:
Originally Posted by boughtonp View Post
Odd choice of matching protocol with (.*) - shouldn't it just be:
Code:
RewriteCond %{HTTP_REFERER} https?://(.*)/
(Along with %1 instead of %2 in the RewriteRule)
It should work the same.
 
Old 08-29-2019, 03:53 PM   #7
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 137

Rep: Reputation: 66
It will work the same (on the surface) (for almost all inputs), but it's an odd way to write something that is clearer when explicit, (or that can actually be omitted entirely due to the way RewriteCond works).

However, what could make it not behave as (most likely) desired is the final slash...
Code:
http://example.com/  -> example.com
http://example.com/dir/ -> example.com/dir
http://example.com/file    -> no match
If the aim is to strip the protocol, then the slash should be removed to allow the third line to match

More likely the aim is to just get the domain, in which case the condition only needs to be:
Code:
RewriteCond %{HTTP_REFERER} //([^/]+)
Since RewriteCond doesn't anchor its matches to the start or end of the string, the double slash is enough to identify the start of the domain and the anything-except-slash will match upto the path. (It may or not be desirable to exclude any non-default port with //([^/:]+) too.)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.htaccess Help GUIPenguin Linux - Security 6 02-22-2005 03:25 PM
.htaccess help, passwords dont work Atrocity Linux - General 4 07-04-2004 05:22 PM
.htaccess driving me crazy! Help! WorldBuilder Linux - Networking 9 09-18-2003 09:20 AM
htaccess help skillcoyne Linux - General 4 04-02-2003 04:46 PM
Help with .htpasswd and .htaccess MikeeX Linux - General 3 03-25-2003 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration