0

I have a folder full of legacy files that I need to carry over during a site redesign, but I'd like to keep them all in their own folder, called legacy. If a request comes in for an old URL, such as

/old-project/foo.html

but that isn't found, I'd like the server to check the legacy folder

/legacy/old-project/foo.html

and serve that up before throwing a 404. Thoughts?

wyattdanger
  • 208
  • 1
  • 4

1 Answers1

0

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Google it for more. This gets asked a lot.

Beginners tutorial: http://www.elated.com/articles/mod-rewrite-tutorial-for-absolute-beginners/

Advanced info: http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html

In case that wasn't enough:

RewriteEngine On
RewriteRule ^/old-project/(.*)$ /legacy/old-project/$1

Update, per clarification in comment:

This set of rules should do the trick quite nicely. It only redirects requests that aren't for existing files, symlinks, or directories (for indexing).

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^/old-project/(.*)$ /legacy/old-project/$1 [NC,L]
coreyward
  • 77,547
  • 20
  • 137
  • 166
  • Thanks for the resources. I'm looking into it more. – wyattdanger Jan 19 '11 at 04:10
  • I'm hoping to create a condition and rule which will allow htaccess to dynamically redirect those request which can be found, so that a rule isn't required for each individual file. – wyattdanger Jan 19 '11 at 04:46
  • Thanks Corey. I just found a similar question/answer already on stackoverflow, which I'll add for reference: http://stackoverflow.com/questions/595005/redirect-requests-only-if-the-file-is-not-found – wyattdanger Jan 19 '11 at 05:17