views:

22

answers:

1

Using .htaccess, how do I permanently redirect all not found *.flv files in one directory to a 404.flv file in the same directory. For example:

If this file is not found: example.com/flv/*.flv

Use this file: example.com/flv/404.flv

Here's what I have so far (I'm very bad):

RewriteCond /flv/(.*).flv !-f
RewriteRule ^ /flv/404.flv [L,R=301]

Thanks

A: 

You need two separate conditions. And you want to return a 404 response.

RewriteCond %{REQUEST_URI} ^/flv/.*\.flv$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* %{DOCUMENT_ROOT}/flv/404.flv [L,R=404]
Ignacio Vazquez-Abrams
Hi,For some reason I'm getting an Internal Server error. Do I need to modify anything in here besides the file name and the directory?
Tim
Strange. Check the error log.
Ignacio Vazquez-Abrams
Here's what I get /home/example/public_html/.htaccess: RewriteRule: invalid HTTP response code for flag 'R'
Tim
I guess you're not running httpd 2.2 then. In that case you'll have to point `ErrorDocument 404` to a script and handle it in there.
Ignacio Vazquez-Abrams
I'm using Apache 2.0.63. Can you give me a quick example, to make sure I'm doing it right?Thanks a bunch
Tim
Use something like `ErrorDocument 404 404.php`, and then in the script check the value of `$_SERVER['REQUEST_URI']` to see if it redirected from a missing .flv file, then use `header()` to set the response MIME type, and `readfile()` to stream the file to the client.
Ignacio Vazquez-Abrams
I've upgraded to Apache 2.2. Your solution worked fantastic! Thank you!
Tim