Forum Moderators: phranque
I wish to serve an alternate file to those who are remotely linking.
In .htaccess, would this do it?
RedirectMatch (.*)\.gif$ [domain.net$...]
I no longer have this file type on my server but these requests still are driving up bandwidth due to excessive remote linking.
I think I'm close with:
Redirect 301 .*/.gif [domain.net...]
but I think the wild card part is wrong? Need some help, anybody?
RewriteRule .*\.gif$ - [F]
This will 403 them.
If the referer is important, you can add conditions (with mod_rewrite).
[httpd.apache.org...]
See the section on 'Blocked Inline Images'
404 errors are given to users who type in these old file paths. That's fine, I have a custom error page that offers a site_map and search feature.
I am concerned with the amateur who has C&P the file path and who have embedded it in their email, newsgroup, website etc. I get in excess of 200 of these failed requests daily and I would like to replace all these with a nice little .au file I've made :)
Yes I can use rewrite.
What actually happens with the scenarios you've put forth?
Essentially, we're talking about:
RedirectMatch (.*)\.wav$ [domain.net$...]
You have no more .wav (or .mpg or whatever) files, and you want to redirect to an .au file. Everything looks ok to me except for that $ after domain.net
Another possibility. Does the .wav, .mpg, whatever audio file you're talking about require a plugin? If this is the case maybe the browser has given control to the plugin and it doesn't handle .au files.
[added]
I'm just spewing out possibilities here. Your first post indicated correct syntax; I'm not sure if that $ has to be escaped.
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www\.mydomain\.com$
RewriteCond %{HTTP_REFERER} !^http://mydomain\.com$
RewriteRule \.(jpg¦gif)$ path_to_nice_little_au_file [L]
Note that you may not need the third RewriteCond, or you might need more, depending on how many variations of your domain name can reach your site - I show with and without "www" prefix, which is pretty standard. Also, you only need one "RewriteEngine On" directive, so only include that if you don't already have one.
Late night here - got to go.
Jim
I just tried this - nothing happens.
RedirectMatch (.*)\.mid [domian.net...]
Direct requests for old MIDI files still returns a 404 and webpages that embed my the old files do nothing but show up in my logs as failed requests.
<added> I'll give that a try jdMorgan, thanks all.
Same domain - think about it. If the redirection is OK, then there's some kind of infinite loop going on. Any request for .mid will redirect to your new URL, then the browser requests that one, new redirect, ad infinitum.
So if it's actually an .au what are the results for:
RedirectMatch (.*)\.mid [domian.net...]
When I changed back to the .au file type, jdMorgan's code worked. Terrific!
I actually had pretty much that same code in other directory .htaccess to stop remote linking. It worked, with varied sucess, depending on browser, although sometimes it even stopped the files from being served on my domain - LOL. Course, now I am not using that file type at all.
Thanks again.
<added> RedirectMatch in any form did not seem to work, but then again - maybe I just didn't have it correct.
Upon further testing, jdMorgan's code only works if the file is set to start automatically by <embed> or <bgsound>. Direct path or <a> links from other domains still delivers a 404.
> So if it's actually an .au what are the results for:
RedirectMatch (.*)\.mid [domian.net...]
That's it! LOL. I musta tried every variation except that. Works for all remote linking. Thanks for doing my thinking for me.