Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite question

syntax for switching files remotely?

     
5:42 am on Sep 4, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:5805
votes: 64


I wish to serve an alternate file to those who are remotely linking.
In .htaccess, would this do it?

RedirectMatch (.*)\.gif$ [domain.net$...]

5:32 am on Sept 5, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:5805
votes: 64



I still can't figure it out. I'm using .gif and .jpg as examples, but basically what I wish to do is serve a new file in place of requests for a different file type. These requests use numerous Variations of directory/sub-directory names.

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?

5:57 am on Sept 5, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 10, 2001
posts:748
votes: 0


You were closer on your first one.

Leave out the $, I think, it looks funny.

You're matching anything where the url ends in .gif and redirecting to somewhere else. I don't know if that's the same domain, but it might not like that $ - probably returns 404.

5:58 am on Sept 5, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


keyplyr,

Two questions:

1) How does your method determine that the files are being linked to remotely?
1b) Or do you not really need to determine this (comments in your 2nd post)?
2) Do you have access to mod_rewrite?

Ok, make that three questions... :)

Jim

6:04 am on Sept 5, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 10, 2001
posts:748
votes: 0


I should add this if you have mod_rewrite:

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'

6:11 am on Sept 5, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:5805
votes: 64


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.

6:22 am on Sept 5, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 10, 2001
posts:748
votes: 0


Is it on a different domain? Then you shouldn't have a problem. Maybe it's a prob with the mime/type here. (which I doubt)

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.

6:27 am on Sept 5, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


OK, if the .au's are on the same server, this should do it:

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

6:32 am on Sept 5, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:5805
votes: 64



Same domain. I have also changed the new file to the same filetype as the remote requests (.mid)

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.

6:43 am on Sept 5, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 10, 2001
posts:748
votes: 0


Hope jd's works out. But your post indicated that the requests are for .mid

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...]

6:55 am on Sept 5, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:5805
votes: 64



Yes bobriggs, you're correct. I thought by changing my new file to .mid that it would help, but as you described, it jammed up the browser - hope I didn't crash anyone for the several moments I was experimenting :o

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.

7:48 am on Sept 5, 2002 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:5805
votes: 64


> When I changed back to the .au file type, jdMorgan's code worked.

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.