404 error and redirection

We encountered “File does not exist” problem after we changed the software name from “software_old.exe” to “software_new.exe”, then the http request for the file at “www.my_site.com/download/software_old.exe” always cause 404 error.

Is it possible to redirect the request for “www.my_site.com/download/software_old.exe” to “www.my_site.com/download/software_new.exe”? i.e. user type in address bar “www.my_site.com/download/software_old.exe”, he get “www.my_site.com/download/software_new.exe”

Thanks for help!

One of the reasons I went ahead and paid for The Definitive Guided to Apache mod_rewrite by Bowen is because he’s got a section all about when not to use it : )

Thank you for help. I add Redirect 301 command in .htaccess file, now it works.

If you have access to a .htaccess file, you can force a redirect, like so:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^download/software_old.exe$ http://www.my_site.com/download/software_new.exe [R=301,L]

Thank you, Ralph, and you’re welcome, farmer!

mod_rewrite is a subset of regex made “easy” by “one line” variables that it can access. Where it gets “difficult” is in imagining what can be accomplished with it - better yet, what CAN’T be done with it! As you showed, Ralph, it can do what other tools can do, too, so it’s quite a POWERFUL (and useful) tool!



Great, thanks David. I’m really keen to learn something about this area, as it’s a big world of mystery to me at the moment. I’ve started to read your wonderful sticky thread, which provides a great introduction, I must say.

Good response, Ralph, except:

  1. You don’t need the RewriteCond

  2. mod_rewrite is NOT the correct tool to use for a simple redirect like this.


Redirect 301 /download/software_old.exe /download/software_new.exe

The reason for this is that mod_alias is a part of Apache’s core so it doesn’t need to be loaded nor does it have to go off and load the regex engine, too, i.e., it is much faster.

The first thing to learn about mod_rewrite is when NOT to use this POWERFUL tool.