htaccess mod_rewrite referencing to full path directories
Is it possible to reference a full/absolute path directory, such as /usr/home/public_html/x
in .hta开发者_运维知识库ccess mod_rewrite?
I've tried the most obvious case of putting the following in the .htaccess of a subdomain (stored in a folder in public_html), hoping it'd map (not redirect!) onto the file as pointed by the absolute directory:
RewriteEngine on
RewriteRule /xochotl /usr/home/public_html/x.php
That doesn't work... I get a 500 Internal Server Error
The .htaccess in the main public_html directory simply has the following, and it works with relative directories...
RewritEngine on
RewriteRule /xochotl x.php
You cannot map to a filepath when using mod_rewrite
in a per-directory context (that is, using .htaccess
). You should be able to, however, map to an absolute path when you place your rules in a per-server context (httpd.conf
, either in the main server or virtual server configuration).
The reason for this is because of how mod_rewrite
works in a per-directory context. mod_rewrite
transforms the URL, then assigns itself as the handler for the request. This allows it to send an internal redirect through Apache, which would otherwise not have been possible this late in the processing.
The internal redirection is done through invoking the Apache API function ap_internal_redirect
, which expects a URI that is then remapped to the filesystem. As a side note, this also happens to be why %{REQUEST_URI}
and %{REQUEST_FILENAME}
change when you perform a redirection that involves the same .htaccess
file being read for the subsequent request (e.g. any time .htaccess
is in the site root).
精彩评论