views:

126

answers:

2

This is a follow-up to this question.

I am trying to build a mod_rewrite rule where the rewriting target is an absolute path outside the web root, like

RewriteRule ^manual(/(.*))?$ /www/htdocs/customername/manual/$2 [L]

I need to do this because I can't use Alias in a .htaccess context (shared hosting).

There are responses hinting at this not being possible at all.

Is this true? I can't find any clear info in the manual.

Could somebody clarify when absolute paths are possible, and when they are not?

A: 

The replacement in a RewriteRule is a URL path. An absolute path in the replacement is an absolute URL path, not an absolute file path. If you can't reference a resource (i.e. it doesn't have a URL), then the rewrite engine can't help you.

Instead, try creating a symlink, though you'll need the FollowSymLinks or SymLinksIfOwnerMatch option enabled. If you don't have shell access, you can write a script to create symlinks.

outis
That is not true, the substitution in a `RewriteRule` is normally treated as a file path if possible. See the documentation: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
Martin
modrewrite... According to the API phases at this time it is too late for any URL manipulations. When you manipulate a URL/filename in per-directory context mod_rewrite first rewrites the filename back to its corresponding URL (which is usually impossible, but see the RewriteBase directive below for the trick to achieve this) and then initiates a new internal sub-request with the new URL. This restarts processing of the API phases.
luca
@luca: that section talks about how file paths are turned into URL paths for RewriteRules. It describes RewriteRules as applying to URL paths, and the substitutions as being URL paths. The section Martin links to mentions allowing file paths as substitutions.
outis
+4  A: 

It is certainly possible to use absolute file paths in your server config.

You won't be able to do that in a .htaccess file though, since that would give you access to read files outside your document root, even files from other customers that were supposed to be protected by a <Location ...> block.

Martin
All right, this matches my experiences unfortunately. There is no way to get around the `.htaccess` limitation, correct? Not even if the "target" folder is owned by the current user?
Pekka
There's no way with `RewriteRule` alone, but a symlink (outis' suggestion) would work fine **if** your hosting provider was generous enough to allow `FollowSymlinks` or `SymLinksIfOwnerMatch` to be overridden.
Martin