.htaccess redirect files on a one to one basis

///.htaccess redirect files on a one to one basis

.htaccess redirect files on a one to one basis

Lately I have been going over sites I have helped people with in the past revisiting them if you will, I have also been reevaluating some of my old sites that no longer exist yet still have the domains for. While doing this it dawned on me, that I have allowed some people to host images and other files off some of these old sites, either logos of my own, or whatever the case. Problem is when I took those sites down, either cause I moved hosting providers, or they no longer served a purpose I took everything down. Including those shared files, fortunately many of them I still have. The thing is though I wasn’t about to go into each domain folder and start creating new folders to match the file paths of those now old missing files, besides I like to keep myself organized as possible (for a coder that may seem impossible, but I try). What I wanted to do was just take a domain of mine, one I don’t really do anything with currently and or may never, but one that I know I will not likely let drop in my life time. Is take this domain and just create a folder that will act as a repo for the old files, and future files I will share with others like I have in the past. This way I don’t have to worry as much about making the same mistake twice when and if I ever take down another site.\r\n

\r\n

But one problem remained. How do I take sites I don’t have control over the source of anymore and make the files still work as they once did. Well that as big a problem as it seemed was easily assed by htaccess. For me, I have bout 50 or 60 of my 80 or so domains all pointing towards one global server, so I just created a .htaccess file with rewrite rules and conditions that would apply to the old file path. But for you lets say you have a different domains in different places this will still work none the less you just have to upload your htaccess to multiple places to get it to work.\r\n

\r\n

Anyway, Ill stop rambling on and just give you the example you really want.

\r\n\r\n
\r\n\r\nRewriteEngine On\r\nRewriteBase /\r\nOptions +FollowSymLinks\r\nRewriteRule ^wp-content/uploads/2010/06/my-old-file.png$ http://shared.hacia.us/my-new-file.png [L,R=301]\r\n\r\n
\r\n\r\nQuestions? Ask in the comments
By | 2014-01-05T10:20:54+00:00 June 3rd, 2012|Code, htaccess|0 Comments

About the Author:

Not much to know about me, I'm a 35+ year old coder, geek, gamer..

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: