views:

130

answers:

2

I want to map a number of directories in a URL:

www.example.com/manual
www.example.com/login

to directories outside the web root.

My web root is

/www/htdocs/customername/site

the manual I want to redirect to is in

/www/customer/some_other_dir/manual

In mod_alias, this would be equal to

Alias /manual /www/customer/some_other_dir/manual

but as I have access only to .htaccess, I can't use Alias, so I have to use mod_rewrite.

What I have got right now after this question is the following:

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

this works in the sense that requests are recognized and redirected properly, but I get a 404 that looks like this (note the absolute path):

The requested URL /www/htdocs/customername/manual/resourcename.htm 
was not found on this server.

However, I have checked with PHP: echo file_exists(...) and that file definitely exists.

why would this be? According to the mod_rewrite docs, this is possible, even in a .htaccess file. I understand that when doing mod_rewrite in .htaccess, there will be an automated prefix, but not to absolute paths, will it?

It shouldn't be a rights problem either: It's not in the web root, but within the FTP tree to which only one user, the main FTP account, has access.

I can change the web root in the control panel anytime, but I want this to work the way I described.

This is shared hosting, so I have no access to the error logs.

I just checked, this is not a wrongful 301 redirection, just an internal rewrite.

+2  A: 

AFAIK mod_rewrite works at the 'protocol' level (meaning on the wire HTTP). So I suspect you are getting HTTP 302 with your directory path in the location.

So I'm afraid you might be stuck unless.. your hosting lets you follow symbolic links; so you can link to that location (assuming you have shell access or this is possible using FTP or your control panel) under your current document root.

Edit: It actually mentions URL-file phase hook in the docs so now I suspect the directory directives aren't allowing enough permissions.

Maxwell Troy Milton King
Nope, mod_rewrite usually works on redirect level only if specifically told so by a `http://` prefixed URL, or the `[R]` flag. Good point though, I will check whether it is wrongly making a redirect instead of a rewrite.
Pekka
No, it seems there is no redirect, this is an internal rewrite.
Pekka
Yep, sorry. You are right. It is internal. But still I think mod_rewrite works at the 'URL' level only.
Maxwell Troy Milton King
A: 

This tells you what you need to know. The requested URL /www/htdocs/customername/manual/resourcename.htm was not found on this server. It interprets RewriteRule ^manual(/(.*))?$ /www/htdocs/customername/manual/$2 [L] to mean rewrite example.com/manual/ as if it were example.com/www/htdocs/customername/manual/.

Try

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

instead.

BaroqueBobcat
The problem with this is that the directory I want to redirect to is outside the web root, so I can't reference it relatively. Let's say I'm in `/www/htdocs/customername/site` and that is the web root. If this is the problem, do you know how can I change this behaviour so that the implicit directory prefix is not used?
Pekka