Results 1 to 2 of 2
I know it can be done, I just don't know how. Because of space and other limits on one box, I am needing to put some of my files on ...
- 04-07-2005 #1Just Joined!
- Join Date
- Apr 2005
- Posts
- 2
Apache Rewrite IF not on 1, THEN pull from 2
I know it can be done, I just don't know how. Because of space and other limits on one box, I am needing to put some of my files on another box. I would like to be able to continue coding my pages to pull all URL's as if they were on one box. In short then, IF /server1/path/ exists THEN serve. IF /server1/path/ does NOT exist, THEN /server2/path/. I realize it's possible to get a 404 then in the end but I need it to at least try on the second server. The reason I don't want to just code the links to /server2/path/ is because I hope to eventually be able to put everything back together on one server.
I already use:
because I've been changing the format of my pages. Old pages were named .htm and new ones are .html but in case there's a link laying around to a .htm that's been converted, this will take care of it. At the same time, as I make the new pages, I'm coding them to pull .html but in case I've not made the new .html, it will pull the .htm. Yes, I realize this could cause a 500 error but I'll deal with a couple 500's vs a whole bunch of 404's.Code:RewriteCond %{REQUEST_URI} \.htm$ RewriteCond /path/to/files%{REQUEST_URI} !-f Rewriterule ^(.*)\.htm$ /$1.html [L] RewriteCond %{REQUEST_URI} \.html$ RewriteCond /path/to/files%{REQUEST_URI} !-f Rewriterule ^(.*)\.html$ /$1.htm [L]
I've been looking around and have found:
Code:# Search in multi-directories RewriteCond /path/to/files/%{REQUEST_FILENAME} -f RewriteRule ^(.+) /path/to/files/$1 [L] RewriteCond http://server2/%{REQUEST_FILENAME} -f RewriteRule ^(.+) http://server2/$1 [L] RewriteRule ^(.+) - [PT]
I can't get either to work though. Right now I'm just trying to simply pull a file from server2's webroot and can't seem to get it to work. ....then I need to hope it will work with deeper paths.Code:# Redirect Failing URLs To Other Webserver RewriteCond /path/to/files/%{REQUEST_FILENAME} !-f RewriteRule ^(.+) http://server2/$1
Trying to get:
http://server1/image.jpg (which doesn't exist) to pull
http://server2/image.jpg since it doesn't exist on server1
I'm trying to get it to go even one step further and...
http://server1/path/to/image.jpg
use the path/to/image.jpg to then try
http://server2/path/to/image.jpg
If it matters, or better yet, if it can be forced, I'm only needing this to work with jpg files at the moment. I can leave all of the html files on server1.[/code]
- 04-07-2005 #2Just Joined!
- Join Date
- Apr 2005
- Posts
- 2
*hopefully resolved
I think I've got it. Now to just tweak the second server to use the error page from the first and it should be good to go.
So what worked?....
The order in .htaccess DOES make a difference too.
I don't know if that last line really needs to be there thoughCode:RewriteCond %{REQUEST_URI} \.htm$ RewriteCond /path/to/htdocs%{REQUEST_URI} !-f Rewriterule ^(.*)\.htm$ /$1.html [L] RewriteCond %{REQUEST_URI} \.html$ RewriteCond /path/to/htdocs%{REQUEST_URI} !-f Rewriterule ^(.*)\.html$ /$1.htm [L] RewriteCond %{REQUEST_URI} \.jpg$ RewriteCond /path/to/htdocs%{REQUEST_URI} !-f RewriteRule ^(.+) http://server2/$1 [L] RewriteRule ^(.+) - [PT]


Reply With Quote
