Directory level .htaccess mod_rewrite stops vhost rewrites
The following directive in my vhost
file works fine when there is no .htaccess
file. But, when I introduce one it stops working. How do I get the vhost
rewrites to execute when the htaccess
rewrite is not-matched
?
From vhost.conf
:
# Skip everything except html and json
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.(html|json)$
RewriteRule .* - [L]
# If html exists (is cached)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
# Otherwise pass it on the index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
From /test/.htaccess
:
RewriteEngine on
RewriteCond %{REQUEST_URI} old_directory/.*$
RewriteRule (.*)$ old_missing.phtml [PT]
Requests for /test/hello.json
...
.htaccess
: is routed to index.php
and returns the correct json.
...with .htaccess
: returns a 404 Not Found
Requests for /text/old_hello.phtml
...
.htaccess
: returns a 404 Not Found
...with .htaccess
: returns the contents of old_missing.phtml
Also, I tailed my rewrite log and it looks like it's doing what it should with the .htaccess
rules (trip per-dir prefix
, applying pattern
, RewriteCond => not-matched
, and pass through
), but then it just stops.
For those who are inclined to ask "Why are you doing this?" there are two reasons 1) I'm getting paid and 2) we are migrating some ajax .phtml
requests to a new ajax .json
system so we need to pass back a message if the user is requesting files from the old_directory
开发者_开发问答 to first inform them of the changes. Thanks.
You need to add the following line into ALL your .htaccess files where you use Rewrite Rules:
RewriteOptions inherit
Apache documentation: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions
精彩评论