How come I can't move the contents of my .htaccess file into my virtual host?
RewriteBase does not work in virtualhost files.
The question you probably want to ask is:
How do I include relative paths in VHost RewriteRules?
Particularly, in vhosts, *_FILENAME returns a slash followed by the REQUEST_URI, instead of being relative or mapped to the filesystem!
Eg, %{SCRIPT_FILENAME}
- In .htaccess: "assets/style.css"
- In a vhost file: "/assets/style.css"
- You need: "/var/www/assets/style.css"
There are several solutions:
Solution #1: %{DOCUMENT_ROOT}
RewriteRule ^/foo/bar$ %{DOCUMENT_ROOT}/foo/bazRewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-fRewriteRule (.*) /script.cgi
Solution #2:
<Directory> tags
RewriteEngine On<Directory "/var/www/"> ... RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule (.*) /script.cgi</Directory>
Within the directory tag, *_FILENAME is treated the same as in a htaccess file.
There may be an issue using this when the server has multiple aliases.Solution #3: %{REQUEST_URI}
Use %{_URI} instead of %{_FILENAME} where possible
Not a real answer. Just pointing out that *_URI's won't have to be rewritten as they are not supposed to map to the filesystem, and therefore vhost/htaccess paths are the same. However, it is not always possible to use REQUEST_URI, and David Faux commented above that it is slower. Besides, thi