Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HTACCESS redirect based on referer

Posted on 2006-11-23
8
Medium Priority
?
362 Views
Last Modified: 2008-01-09
This is what I want to do:

I have a domain: http://www.downhere.com

On that domain I will have a page that links to http://www.downhere.com/download.zip

download.zip does not exist, and will never exist.

If somebody tries to access download.zip (which dosnt exist) and they have a referer that matches my domain,
then I want them to be redirected to setup.zip

The end point is that I want anybody who tries to access download.zip without using a link on my site to get real 404 headers, but if they access the file from the link on my site I want them to be redirected to setup.zip

Thanks
0
Comment
Question by:zattz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 3

Expert Comment

by:joachim.claeys@teleatlas.com
ID: 18003073
If you have mod_rewrite enabled on your webserver:

RewriteCond %{HTTP_referer} ^http://(www\.)?downhere\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://www.downhere.com/download.zip [R=301,L]

First line: check of the referer is your domain
Second line: check if the filename does not exists
Third line: Redirect to the download.zip file if above conditions are met

0
 

Author Comment

by:zattz
ID: 18003144
Umm,

Isnt the third line supposed to say setup.exe?

Also, I only want it to redirect if the file requested was download.zip, i don't want all files that don't exist to redirect to setup.exe
0
 
LVL 3

Expert Comment

by:joachim.claeys@teleatlas.com
ID: 18003267
You mean to setup.zip.

Here's the corrected version:

RewriteCond %{HTTP_referer} ^http://(www\.)?downhere\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://www.downhere.com/setup.zip [R=301,L]

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:zattz
ID: 18003441
Yes I meant setup.zip :)

How come I don't see download.zip mentioned in any of the lines? I don't want all files that dont exist to be redirected?
0
 
LVL 3

Expert Comment

by:joachim.claeys@teleatlas.com
ID: 18003525
RewriteCond %{HTTP_referer} ^http://(www\.)?downhere\.com [NC]
RewriteCond %{REQUEST_FILENAME} ^download.zip [NC]
RewriteRule (.*) http://www.downhere.com/setup.zip [R=301,L]

Untested ;-|

0
 

Author Comment

by:zattz
ID: 18003609
This works:

options all
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_referer} ^http://(www\.)?downhere.com\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule download.zip http://downhere.com.com/setup.zip [R=301,L]

BUT i'm getting some strange behaviour.

When I visit the webpage and click the link, it downloads correctly.
But then if I try and access download.zip directly without clicking the link i get the 404 which I should.
But then if I got back to the page and click the link I get a 404!

But if I go to another computer with another IP and click the link there, it works, and then after doing it, the other pc works too! until it tries to access download.zip directly again!

any ideas?
0
 
LVL 3

Accepted Solution

by:
joachim.claeys@teleatlas.com earned 1500 total points
ID: 18003975
The last line contains an typing error ( the domainname ) :
RewriteRule download.zip http://downhere.com.com/setup.zip [R=301,L]

should probably be
RewriteRule download.zip http://www.downhere.com/setup.zip [R=301,L]

0
 

Author Comment

by:zattz
ID: 18003992
I fixed that before I use it... but the problem above is still there...

I have tried it with two webhosts... very weird.

I will accept your answer anyway, as its not your fault what I wanted to do dosnt work properly ;)

If you have any ideas please comment
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question