Forum Moderators: phranque

Message Too Old, No Replies

Sending users to pages based on refferer

How to

         

hurlimann

12:34 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



I need to send users who click on certain external links to our site to a special page and not the page the link is to.

What's the best way of doing this in an HTA file?

jatar_k

9:23 pm on Jan 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I assume HTA is htaccess?

I don't really know how to do it with htaccess but you can do it with a script though it probably wouldn't be 100%.

if($_SERVER['$HTTP_REFERER'] == "sompage") {
header(Location: http:*//www.somesite.com/page.html);
}

Would work most times.

hurlimann

10:31 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



Ta this is what my main programmer suggested.

jatar_k

10:36 pm on Jan 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's not 100%

from php.net on HTTP_REFERER

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

but it should be a little more reliable when you know exactly what page you are getting referred from.

andreasfriedrich

10:43 pm on Jan 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your .htaccess file you could use mod_rewrite to redirect users depending on the referrer. The example Browser Dependend Content in the URL Rewriting Guide [httpd.apache.org] could be adjusted with minimal effort to achieve just what your want.

Andreas

hurlimann

10:48 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



Ta it was suggested by Brett to use htaccess so maybe he thinks it is more relaible than a script. ( He may have suggested it as he knew why I needed to do this).

Brett_Tabke

11:19 pm on Jan 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can do a redirect from that directory

Redirect 301 /opera [webmasterworld.com...]

example:
[searchengineworld.com...]

hurlimann

11:21 pm on Jan 30, 2003 (gmt 0)

10+ Year Member



I am totally confused ( proably as I didn't explain it correctly:

Some domains and their pages (outwith our control) link to our site. I want people clicking on these links to be sent to a special page on our domain explaining the link is unauthorised and not to the pages the link is to.

I want genuine inbound links to be uneffected.

How is this done in htaccess and is this a better method than a script?

hurlimann

12:55 pm on Feb 1, 2003 (gmt 0)

10+ Year Member



Bumped as I still cant solve this!

andreasfriedrich

1:08 pm on Feb 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you have a look at the example I referred you to? With minimal changes to the code you could come up with code like this:

RewriteCond %{HTTP_REFERER} ^http://www\.bad1\.com [OR] 
RewriteCond %{HTTP_REFERER} ^http://www\.bad2\.com
RewriteRule .* /path/to/bad_page.html [R=301,L]

It will redirect people to bad_page when the request header contains a referer field matching [bad[1¦2].com....]

Andreas

hurlimann

6:11 pm on Feb 1, 2003 (gmt 0)

10+ Year Member



Thanks I will get a tech to try this in the HTaccess

hurlimann

3:59 pm on Feb 2, 2003 (gmt 0)

10+ Year Member



R we doing this right as we can't get it to work. We used

RewriteCond %{HTTP_REFERER} ^http://www\.domain\.domain\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://domain\.domain\.com
RewriteRule .* /failed.html [R=301,L]

We also tried without the [xyz ]bits.

Ta

hurlimann

5:48 pm on Feb 3, 2003 (gmt 0)

10+ Year Member



Still trying and failing :(

Key_Master

6:03 pm on Feb 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SetEnvIfNoCase Referer ^(http://www\.¦http://)domain\.domain\.com ban

<Files ~ "^.*$">
order allow,deny
allow from all
deny from env=ban
</Files>

The .htaccess code above will block referrers that begin with http:*//www.domain.domain.com and http:*//domain.domain.com . They will be redirected to a 403 page instead. If you have a custom error 403 page you can list a number of reasons why they might have been banned and include a link to your home page so the visitors can continue to surf on your site.

<added>Remember the broken pipe (¦) needs to be replaced with a solid vertical pipe.</added>

andreasfriedrich

12:18 pm on Feb 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you doing this in the httpd.conf file or in a .htaccess file?

Do you have root access?

If so is mod_rewrite loaded and enabled like so:


LoadModule rewrite_module /usr/lib/apache/1.3/mod_rewrite.so
RewriteEngine on

Of course you would need to adjust the path to the rewrite module.

Key_Master´s solution would work as well. The only draw back is that you are not free to redirect people to any page you want. But it depends only on modules that are compiled and enabled by default.

HTH Andreas

hurlimann

1:27 pm on Feb 4, 2003 (gmt 0)

10+ Year Member



In the htaccess file.

We do not have root access.

mod_rewrite loaded and enabled like stated ( in root mode)

Unfortuntatly Keymasters 403 idea whilst working, doesn't achieve what we need to do in this case.

andreasfriedrich

1:51 pm on Feb 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here are some things you might want to check hurlimann:


Options +FollowSymLinks
RewriteEngine on

You might want to include the above lines into your .htaccess file.

Make sure that there are no matching RewriteRules with a [L] flag before the rules that should do the redirect.

Options +FollowSymLinks will only work when you have AllowOverride Options privileges which must be granted in the httpd.conf file.

Make sure that Apache actually reads the .htaccess file. This is easily checked by using some unknown directive. When Apache reads this it will return a 500 Internal Server Error.

Have you been using mod_rewrite on this site before and has it been working?

Andreas