force redirect?!

New to mod_rewrite? This is a good place to start.

force redirect?!

Postby BMN » Thu Feb 10, 2011 9:01 am

Hi there, i just setup a subdomain "data.domain.org".
Now i want to track my page with an analytic-tool - this is functional with this structure:
- i only share links on the internet with the url to e.g. "domain.org/img/1.jpg"
- this page includes a 404.php, in which the javascript of the analytic-tool is in it - this 404.php redirects to "data.domain.org/img/1.jpg"

So, normally this is, what i want! BUT: if someone shares the link on his own, he will share it with the subdomain and then the javascript won't be run und i can't track my visitors, 'cause the directlink...

Now i want to fix this problem with mod_rewrite, that on demand of e.g. "data.domain.org/img/1.jpg" the user gets redirected to "domain.org/img/1.jpg" - then the 404.php gets included and the anayltic-tool tracks this visitor - to exit the loop mod_rewirte should only fire on a referer that is not domain.org.

This is my test-code in .htaccess (without referer-check but thats simple, i hope :D)

Code: Select all
    RewriteEngine on
    Redirect 301 /http://data.domain.org/* http://domain.org/*


Easy code, but this is only functional on links, they're not exists. How i can realize, that mod_rewrite forces redirecting, so long the referer is not domain.org?

My problem simply described:
data.domain.org/img/1.jpg --> referer != domain.org? --> domain.org/img/1.jpg --> include javascript --> data.domain.org/img/1.jpg (referer = domain.org, so no more redirect!)

Thanks in advance!
BMN
 
Posts: 39
Joined: Wed Jul 05, 2006 2:15 am

Return to Beginner's Corner

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests

cron