.htaccess vs VirtualHost

Rules That Work in .htaccess but Not in a Virtual Host

Rules moved into <VirtualHost> run faster (Moving Rules to Config) but before the URL is mapped to a file. configtest accepts the four rewrite lines of Override Classes pasted there unchanged, and both rules then fail, as responses and trace show:

Output of 86
/old-blog/2026/post.html  200  front controller: /old-blog/2026/post.html
/css/site.css             200  front controller: /css/site.css
trace3 applying pattern '^old-blog/(.*)$' to uri '/old-blog/2026/post.html'
trace4 RewriteCond: input='/css/site.css' pattern='!-f' => matched

The pattern sees the path with its leading slash, so ^old-blog/ never matches. And REQUEST_FILENAME is not yet a file path; the manual says it equals REQUEST_URI here, so !-f looked for /css/site.css at the file system's root. These lines redirected the old URL and served the stylesheet:

Section 2.4.6's rewrite lines, written for virtual-host contextApache config
RewriteEngine On
RewriteRule ^/old-blog/(.*)$ /blog/$1 [R=301,L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^ /index.php [L]

RewriteBase there fails configtest, and server-wide rules need RewriteOptions Inherit. To move a file unedited, wrap it in <Directory> instead (Moving Rules to Config).