You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Borden Rhodes <jr...@bordenrhodes.com> on 2014/01/02 03:55:48 UTC

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

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


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