homepage Welcome to WebmasterWorld Guest from 54.161.191.254
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod rewrite question
syntax for switching files remotely?
keyplyr




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

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

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

 

keyplyr




msg:1509924
 5:32 am on Sep 5, 2002 (gmt 0)


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?

bobriggs




msg:1509925
 5:57 am on Sep 5, 2002 (gmt 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.

jdMorgan




msg:1509926
 5:58 am on Sep 5, 2002 (gmt 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

bobriggs




msg:1509927
 6:04 am on Sep 5, 2002 (gmt 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'

keyplyr




msg:1509928
 6:11 am on Sep 5, 2002 (gmt 0)

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.

bobriggs




msg:1509929
 6:22 am on Sep 5, 2002 (gmt 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.

jdMorgan




msg:1509930
 6:27 am on Sep 5, 2002 (gmt 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

keyplyr




msg:1509931
 6:32 am on Sep 5, 2002 (gmt 0)


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.

bobriggs




msg:1509932
 6:43 am on Sep 5, 2002 (gmt 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...]

keyplyr




msg:1509933
 6:55 am on Sep 5, 2002 (gmt 0)


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.

keyplyr




msg:1509934
 7:48 am on Sep 5, 2002 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved