Forum Moderators: phranque

Message Too Old, No Replies

.htaccess - redirecting requests

         

bluesting

9:14 am on Jul 25, 2006 (gmt 0)

10+ Year Member



Hi,

For me, this is a little too tough, I got it right once but it was a while ago!

I have 2 websites "primary" and "secondary". The "secondary" website must "share" images with the "primary" website, for purposes of saving space on a shared host!

So, ALL requests to "secondary/images/items" must be sent to "primary/images/items".

But, here are the catches:

1) I want to save bandwidth, so it's not a mod_redirect "redirect" [R] statement! It must directly fetch the file from the filesystem on request!

2) I have other folders under the "images" directory that I DON'T want to share! eg. /images/logos ... so JUST the /images/items folder must share files!

3) I use a dynamic image function that uses file_exists('/images/items/1.jpg') AND fopen('/images/items/1.jpg') that MUST work!

I have tried the following:

Alias /items ../../primary/images/items
RewriteRule ^/images/items/(.*)$ ../../primary/images/items/$1
DocumentRoot ../../primary/images/items

Which of these should I pursue further ... the differences are confusing!

bluesting

10:09 am on Jul 25, 2006 (gmt 0)

10+ Year Member



Hi,

I keep getting an "Internal Server Error" when I use Alias. I have got "Options Indexes FollowSymLinks MultiViews ExecCGI" set for the directory.

Statements like this:

Alias /images/items /images/test

should redirect the call to that directory ... not so? The "/images/items" does not exist, but the "/images/test" does!

jdMorgan

12:57 pm on Jul 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alias /images/items /images/test

In this case /images/items is a URL-path, and so is relative to the document root.
But /images/test is a local-filepath, and so is relative to the Apache installation directory.

Without looking at your server error log, in which the specific 500-Server Error reason will be logged, my best guess is that the local-filepath is missing a directory element (one or more), and that it's therefore not resolving to the correct directory.

Alias does not invoke a redirect, it simply changes the filepath associated with a requested URL-path. The same thing is true of the internal rewrite variant of RewriteRule, as opposed to the external redirect (mod_rewrite can do either).

To my knowledge, relative filepaths are not supported by mod_rewrite or DocumentRoot directives, so that ../ stuff won't work.

If you are not using content-negotiation, do not enable MultiViews... This can be a big time-waster, and lead to duplicate-content issues and other unexpected server behaviour.

Jim