RewriteEngine On
RewriteCond %{REQUEST_URI} !^/cache/
RewriteRule ^(.*)$ /cache/$1
#我想要如果匹配到 /cache/$1 的话就此结束
#若没有匹配到 /cache/$1 的话就执行下面的那个 index.php
RewriteRule ^ index.php [QSA,L]
目录结构
/root
-cache
|-test.txt
-index.php
-.htaccess
比如访问 /test.txt ,就能直接访问到 /cache/test.txt ,若访问 /hello.txt 就重写成 /index.php?blahblahblah
该如何实现呢?
最后还是自己解决了
RewriteEngine On
RewriteRule !^cache/ cache%{REQUEST_URI}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
参考: http://stackoverflow.com/questions/1165341/apache-rewriterule-to-subdirectory