httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Evans <tevans...@googlemail.com>
Subject Re: [users@httpd] Curious inability to mod_rewrite absolute paths
Date Wed, 27 Nov 2013 10:32:59 GMT
On Wed, Nov 27, 2013 at 5:37 AM, Borden Rhodes <jrvp@bordenrhodes.com> wrote:
> Good evening,
>
> I thought that I had worded my question clearly. Is there something
> wrong with how I've asked my question or that I'm asking for something
> very unusual?
>
> I'll do my best to give you all of the information you need:
>
> I've copied a Drupal 6 website from a public webserver into my own
> webserver under /home/borden/www/clientWork/Drupal/ folder . My
> apache.conf file sets up a VirtualHost with DocumentRoot set to
> /home/borden/www . Therefore, when I want to browse the website on my
> local server, I point Firefox to http://localhost/ClientWork/Drupal/
> which takes me to my local copy of the website.
>
> However, for various reasons, some images on the Drupal website are
> hardlinked to "/sites/default/files/images/..." This works fine on the
> public server, but on my local server, it's trying to fetch files from
> "http://localhost/ClientWork/Drupal/sites/default/files/images/"
> which, of course, is a non-existent folder.
>
> What I want to do is write an .htaccess rule so that, when Firefox
> requests the image at "/sites/default/files/images/...", Apache
> fetches the file at
> "http://localhost/ClientWork/Drupal/sites/default/files/images/..."
>
> I do not want to affect the server globally because I have other
> websites I fiddle with on this server, all neatly contained in their
> own folders. This rewrite rule I want only to apply to absolute links
> under "http://localhost/ClientWork/Drupal/" and not touch the other
> folders.
>
> If this is beyond Apache's capabilities, just let me know, and I'll
> try to find a way to trick the server using symlinks. If my request is
> still confusing, please help me explain my problem so that it can be
> understood.
>
> With thanks,
>

So, to clarify.

When you go to "http://localhost/ClientWork/Drupal/", it has <img>
tags with absolute URLs of
"http://localhost/sites/default/files/images/".

You want requests for "http://localhost/sites/default/files/images/"
to be rewritten to
"http://localhost/ClientWork/Drupal/sites/default/files/images/".

You only want this redirection to happen to links 'under
"http://localhost/ClientWork/Drupal/"'.

The first requirement is trivial:

Alias /sites/default/files/images
/home/borden/www/ClientWork/Drupal/sites/default/files/images

The second requirement is impossible to achieve with mod_rewrite,
which is a tool for rewriting *requests*. HTTP is stateless, so a
request for "/sites/default/files/images/" is just that, it is not
"under" anything.
In order to only make your changes apply to pages "under" one URL
path, you would need to rewrite the *response* so that the URLs are
correct in the first place and you do not need to rewrite the
subsequent requests.

The easiest way to do that would be to fix your drupal installation so
it generates the right content to start with.

Cheers

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message