Forum Moderators: phranque

Message Too Old, No Replies

conditional alias?

Any way to conditionally alias my includes directory?

         

RufusM

7:00 pm on Aug 4, 2005 (gmt 0)

10+ Year Member



I have an apache 1.3 site running on Linux.

The site's pages use a set of template files (header, footer, etc.) held in the /includes directory. Files calling these includes are all over my webtree and use root-relative references to find them.

I am now developing a new set of template files, to eventually replace the existing ones. These are currently at /new/includes/. The files which call these are held only in one directory, /subfoldera.

However, I want the files at /subfoldera to use the same include reference paths as files using the old templates so that when these files are moved out all over the webspace, and the includes at /new/includes replace those at /includes, it is not necessary to change all the include references within the files from /new/includes to /includes.

i.e. for material in subfoldera only I want to be able to use '/includes' now and for this to be resolved as '/new/includes'.

How can this be done?

mod_rewrite does conditional matching, but can't rewrite includes as these are handled within the server filespace not the webspace.

mod_alias can alias /includes to /new/includes but how do I get the conditional subfoldera in there? (The Alias directive only works within the server and virtual host contexts.)

Can I somehow pass the Remote Condition through to mod_alias using the Pass Through [PT] flag?

Any other options? The only workable alternative I could think of was to call my new template files by different names to those of my old template files and host them in the existing /includes directory, but because the original names need to persist for other reasons (they are resources used by other sites not run by me) they will need to be changed back, which is no saving of effort over changing the directory part of the path reference. Though I could perhaps handle the persistence issue with permanent aliases for the files once the new template rollout is complete.

Does anyone have any better suggestions?

jd01

10:25 pm on Aug 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could do this by switching from a relative include location to a full canonical URL and then use mod_rewrite...

The switch forces the php request for the file to be external, which allows mod_rewrite to act on the requested include file.

Justin

RufusM

1:55 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



Thanks for the suggestion, Justin. Unfortunately, I haven't been able to get this to work either. However I'm using SSI rather than PHP, though I don't see how this logically makes a difference. I tried the below rewrite rule in a .htaccess file in my webroot directory:

RewriteCond %{REQUEST_URI} ^/subfoldera.*
RewriteRule ^includes/(.*) /new/includes/$1

but I'm wondering if this is just a no-go because the condition relates to the first call of the page from the subfoldera directory, whereas the rewrite is for the second call, within that page, for the included template file. If this is the problem, I can't see any way to fix it, unless there is another variable besides REQUEST_URI which represents the page containing an include reference (which is the condition I need to match for)?

jd01

8:37 pm on Aug 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My fault... I did not realize you were using ssi - the path needs to be http://yoursite.com/blah to send the request through the server...

We could probably work around this by including a php file, which only has the purpose of including the actual include file.

EG change your ssi to

<!--#include virtual="/yourfile.php?include=http://yoursite.com/include.file" -->

In yourfile.php <?php include "$include";?>

This will bounce the request to the server and then you can use any server directive you wish on the file path, etc.

Kind of messy, but it's the only way I can see to get to the external processing we need to be able to invoke a rewrite on the file.

Justin

More efficient than changing all of those files to http:

<!--#include virtual="/yourfile.php?include=include.file" -->

In yourfile.php <?php include "http://yoursite.com/$include";?>