You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Tom Evans <te...@googlemail.com> on 2013/12/02 14:02:34 UTC

Re: [users@httpd] Curious inability to mod_rewrite absolute paths

On Sat, Nov 30, 2013 at 12:51 PM, Eric Covener <co...@gmail.com> wrote:
> On Sat, Nov 30, 2013 at 2:53 AM, Borden Rhodes <jr...@bordenrhodes.com> wrote:
>> Assuming that the above steps accurately represent the exchange
>> between Ff and httpd, am I to understand that there's no way to tell
>> httpd in a .htaccess file at step 3 that a request in the form
>> http://localhost/s/d/f/i/... should look for the file at
>> ~/www/CWD/D/s/d/f/i/... ?
>
> You can do that with just Alias if there's no dynamic part.
>

He only wants that to happen if the request "originates from"
/ClientWork/Drupal/ …

You can absolutely tell Apache that requests for
http://localhost/s/d/f/i/ should look in ~/www/CWD/D/s/d/f/i/, what
you can't do is only do that redirection based upon what URL the
previous request was.

However, I refuse to believe that Drupal does not have a setting that
allows you to run it at a particular location and generate the correct
URLs, which is the correct way forward here.
Could you ask this question on a drupal list - and not asking "how do
I redirect XYZ to PQR", but "I installed drupal in /ClientWork/Drupal/
and it is trying to load files from /sites/default/, what have I
missed". There may be a required configuration or installation step
that has been overlooked.

Cheers

Tom

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


Re: [users@httpd] Curious inability to mod_rewrite absolute paths

Posted by Fred Miller <fj...@gmail.com>.
Please take me off this email list. I've already unsubscribed.


On Mon, Dec 30, 2013 at 10:30 PM, Borden Rhodes <jr...@bordenrhodes.com>wrote:

> Good evening, List,
>
> I apologise for not responding. It's been a busy December and I haven't had
> time to fight with httpd. In response to some comments:
>
> On Sat, Nov 30, 2013 at 12:51 PM, Eric Covener <co...@gmail.com> wrote:
> > You can do that with just Alias if there's no dynamic part.
> I may just end up doing this if .htaccess won't let me rewrite paths. I
> wanted
> to leave apache.conf alone and have a RewriteRule in
> /ClientWork/Drupal/.htaccess instead.
>
> As I understand the documentation, Alias is a specialised RewriteRule. If
> so,
> why is the latter allowed in .htaccess but the former is not?
>
> On 2 December 2013 13:02:34 Tom Evans wrote:
> > He only wants that to happen if the request "originates from"
> > /ClientWork/Drupal/ …
> I don't remember saying that I wanted to do this. (I guess this is what
> elicited the 'http is a stateless protocol' response). I don't care where
> the
> request originates from. All I care is that I can put a rule in
> /ClientWork/Drupal/.htaccess that will tell httpd to handle requests to
> "/sites/default/files/..." by retrieving the file at
> "/ClientWork/Drupal/sites/default/files/...".
>
> On 2 December 2013 13:02:34 Tom Evans wrote:
> > You can absolutely tell Apache that requests for
> > http://localhost/s/d/f/i/ should look in ~/www/CWD/D/s/d/f/i/, what
> > you can't do is only do that redirection based upon what URL the
> > previous request was.
> I'm not sure how I gave the impression that the previous request was
> relevant
> to rewriting current requests. Perhaps I caused some confusion when I said
> that the links in question were hard-coded into a Drupal website that lived
> under /ClientWork/Drupal. As I mentioned in earlier messages, I can't get
> any
> variant of "RewriteRule ^/(.*) /ClientWork/Drupal/$1" in
> /ClientWork/Drupal/.htaccess to even catch calls to
> /sites/default/files/...
> let alone rewrite them.
>
> On 2 December 2013 13:02:34 Tom Evans wrote:
> > However, I refuse to believe that Drupal does not have a setting that
> > allows you to run it at a particular location and generate the correct
> > URLs, which is the correct way forward here.
> > Could you ask this question on a drupal list - and not asking "how do
> > I redirect XYZ to PQR", but "I installed drupal in /ClientWork/Drupal/
> > and it is trying to load files from /sites/default/, what have I
> > missed". There may be a required configuration or installation step
> > that has been overlooked.
> Assuming you get a response on the Drupal fora, it'll typically say
> "Install
> module X", where X is an arbitrary member of a set of modules, Y, of
> differing
> levels of stability and maintenance. Even if I can find an X within Y that
> does
> the job, the links I'm trying to rewrite are hard-coded, so any module
> would
> still involve having to go back and rewrite each link by hand.
>
> I agree with you: the way forward is using a Drupal solution. Right now,
> though, I need a working clone of the website so I can do the updates and
> testing that I need to do before taking them live. I would rather have one
> to
> three lines in an .htaccess file work for the time being than to have to
> pick
> through and fix hundreds of pages.
>
> With thanks,
>
> Borden
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Curious inability to mod_rewrite absolute paths

Posted by Borden Rhodes <jr...@bordenrhodes.com>.
Good evening, List,

I apologise for not responding. It's been a busy December and I haven't had 
time to fight with httpd. In response to some comments:

On Sat, Nov 30, 2013 at 12:51 PM, Eric Covener <co...@gmail.com> wrote:
> You can do that with just Alias if there's no dynamic part.
I may just end up doing this if .htaccess won't let me rewrite paths. I wanted 
to leave apache.conf alone and have a RewriteRule in 
/ClientWork/Drupal/.htaccess instead.

As I understand the documentation, Alias is a specialised RewriteRule. If so, 
why is the latter allowed in .htaccess but the former is not?

On 2 December 2013 13:02:34 Tom Evans wrote:
> He only wants that to happen if the request "originates from"
> /ClientWork/Drupal/ …
I don't remember saying that I wanted to do this. (I guess this is what 
elicited the 'http is a stateless protocol' response). I don't care where the 
request originates from. All I care is that I can put a rule in 
/ClientWork/Drupal/.htaccess that will tell httpd to handle requests to 
"/sites/default/files/..." by retrieving the file at 
"/ClientWork/Drupal/sites/default/files/...".

On 2 December 2013 13:02:34 Tom Evans wrote:
> You can absolutely tell Apache that requests for
> http://localhost/s/d/f/i/ should look in ~/www/CWD/D/s/d/f/i/, what
> you can't do is only do that redirection based upon what URL the
> previous request was.
I'm not sure how I gave the impression that the previous request was relevant 
to rewriting current requests. Perhaps I caused some confusion when I said 
that the links in question were hard-coded into a Drupal website that lived 
under /ClientWork/Drupal. As I mentioned in earlier messages, I can't get any 
variant of "RewriteRule ^/(.*) /ClientWork/Drupal/$1" in 
/ClientWork/Drupal/.htaccess to even catch calls to /sites/default/files/... 
let alone rewrite them.

On 2 December 2013 13:02:34 Tom Evans wrote:
> However, I refuse to believe that Drupal does not have a setting that
> allows you to run it at a particular location and generate the correct
> URLs, which is the correct way forward here.
> Could you ask this question on a drupal list - and not asking "how do
> I redirect XYZ to PQR", but "I installed drupal in /ClientWork/Drupal/
> and it is trying to load files from /sites/default/, what have I
> missed". There may be a required configuration or installation step
> that has been overlooked.
Assuming you get a response on the Drupal fora, it'll typically say "Install 
module X", where X is an arbitrary member of a set of modules, Y, of differing 
levels of stability and maintenance. Even if I can find an X within Y that does 
the job, the links I'm trying to rewrite are hard-coded, so any module would 
still involve having to go back and rewrite each link by hand.

I agree with you: the way forward is using a Drupal solution. Right now, 
though, I need a working clone of the website so I can do the updates and 
testing that I need to do before taking them live. I would rather have one to 
three lines in an .htaccess file work for the time being than to have to pick 
through and fix hundreds of pages.

With thanks,

Borden

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


Re: [users@httpd] Re: Curious inability to mod_rewrite absolute paths

Posted by Pete Houston <ph...@openstrike.co.uk>.
On Mon, Jan 06, 2014 at 12:45:27AM -0500, Borden Rhodes wrote:
> I understand from the docs that Alias directives can't be used in .htaccess 
> files. Is this correct? This inability is partly why I kept struggling with 
> RewriteRules - the other was to force myself to practise regexes and advanced 
> configuration. 

It is correct. However, the Redirect directive is permitted in access
files and that too is provided by mod_alias.
http://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect

HTH,

Pete
-- 
Openstrike - improving business through open source
http://www.openstrike.co.uk/ or call 01722 770036 / 07092 020107

[users@httpd] Re: Curious inability to mod_rewrite absolute paths

Posted by Borden Rhodes <jr...@bordenrhodes.com>.
> Because the absolute path does not go anywhere near the "dummy"
> directory which is where your .htaccess file is, so the .htaccess file
> never gets read for that request.
Aaaahhhhhhhh. OK. Thanks! That clarifies a *lot* of things - and makes perfect 
sense, too. It seems that I somehow got into the mindset that, since the image 
file was being requested from within a file located in the same folder as 
.htaccess, that .htaccess would apply against those requested files. However, 
this would mean that httpd would have to keep track of the referrers, which, I 
think, is what Tom warned me that I was trying to do but I misunderstood.

If I've read it correctly, /docs/current/getting-started.html gives a summary 
of how the HTTP client/server relationship works and a very high-level 
overview of HTTP. The documentation may benefit from a diagram or 'sample 
conversation' between a client and server so that people new to httpd (like 
me) understand exactly what httpd does and, more importantly, what it doesn't 
do. I checked Safari and couldn't really find a book that explains httpd beyond 
how to install it on a particular system. Perhaps adding this theory to the 
Apache doc would help people like me get into the correct paradigm? If so, 
I'll try to 'repay' by suggesting changes to the docs unless someone can 
suggest a resource that I *should* have consulted first to help me understand 
how HTTP and httpd work.

> Put your .htaccess file somewhere that it will actually be read for the
> requests which you want it to affect.
Which means that I'm right back to changing the VirtualHost configuration, but 
at least I understand now why it has to work this way.

> BTW, you don't need mod_rewrite for this sort of redirection. mod_alias
> would do just as well and be more lightweight and less confusing. Your
> choice, however.
I understand from the docs that Alias directives can't be used in .htaccess 
files. Is this correct? This inability is partly why I kept struggling with 
RewriteRules - the other was to force myself to practise regexes and advanced 
configuration. 

> All the best,
> 
> Pete

Much obliged and grateful.

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


Re: [users@httpd] Re: Curious inability to mod_rewrite absolute paths

Posted by Pete Houston <ph...@openstrike.co.uk>.
On Wed, Jan 01, 2014 at 09:55:48PM -0500, Borden Rhodes wrote:
> I notice in the log that httpd passes the requests for the first two images 
> through RewriteRule in the .htaccess file. However, the call to fetch 
> /images/bowler.jpeg *doesn't* go through the RewriteRule, but instead (line 50 
> in the log) goes straight through protocol.c and, predictably, fails. This 
> raises three questions:
> 
> 1) Why is the absolute path *not* being passed through a rewrite rule but the 
> other two requests are?

Because the absolute path does not go anywhere near the "dummy"
directory which is where your .htaccess file is, so the .htaccess file
never gets read for that request.

> 2) Can I change this behaviour from an .htaccess file?
> 3) If so, how?

Put your .htaccess file somewhere that it will actually be read for the
requests which you want it to affect.

BTW, you don't need mod_rewrite for this sort of redirection. mod_alias
would do just as well and be more lightweight and less confusing. Your
choice, however.

All the best,

Pete
-- 
Openstrike - improving business through open source
http://www.openstrike.co.uk/ or call 01722 770036 / 07092 020107

[users@httpd] Re: Curious inability to mod_rewrite absolute paths

Posted by Borden Rhodes <jr...@bordenrhodes.com>.
Happy New Year, all!

Perhaps phrasing my question using this demonstration will make my problem 
clearer:

I set up a dummy website on my server under a "dummy" folder. Therefore, from 
Firefox, to the dummy, I go to "http://localhost/dummy/". dummy/index.html 
says:

# Begin index.html
<!DOCTYPE html>

<html>
<head>
  <title>Dummy</title>
  <meta charset="utf-8"/>
</head>
<body>
  <p>
    <img src="http://localhost/dummy/images/bowler.jpeg" 
alt="http://localhost/dummy/images/bowler.jpeg" /><br />
    <img src="images/bowler.jpeg" alt="images/bowler.jpeg" /><br />
    <img src="/images/bowler.jpeg" alt="/images/bowler.jpeg" /><br />
  </p>
</body>
</html>
# End index.html

dummy/images/bowler.jpeg exists and is a picture of my favourite hat.

I also have dummy/.htaccess :

# Begin .htaccess
Options FollowSymLinks

RewriteEngine On
RewriteRule /images/bowler.jpeg images/bowler.jpeg
# Begin .htaccess

So, I point Firefox to http://localhost/dummy/ and I get a page with two 
bowlers followed by the text "/images/bowler.jpeg". I cranked LogLevel to 
trace8 and put its output here: http://pastebin.com/ZnFBvzrA .

I notice in the log that httpd passes the requests for the first two images 
through RewriteRule in the .htaccess file. However, the call to fetch 
/images/bowler.jpeg *doesn't* go through the RewriteRule, but instead (line 50 
in the log) goes straight through protocol.c and, predictably, fails. This 
raises three questions:

1) Why is the absolute path *not* being passed through a rewrite rule but the 
other two requests are?
2) Can I change this behaviour from an .htaccess file?
3) If so, how?

With thanks,

Borden

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