Mod rewrite 重写静态内容的URL

Mod rewrite 重写静态内容的URL,mod-rewrite,apache2,Mod Rewrite,Apache2,我在apache2上当前的.htaccess设置中重写静态文件url时遇到问题 我的应用程序结构是: /siteroot /siteroot/app /siteroot/lib /siteroot/... /siteroot/public <- all the static files (images, js, etc.) stored here /siteroot/index.php /siteroot/.htaccess 测试重定向是否合理: RewriteCond %{REQUES

我在apache2上当前的.htaccess设置中重写静态文件url时遇到问题

我的应用程序结构是:

/siteroot
/siteroot/app
/siteroot/lib
/siteroot/...
/siteroot/public <- all the static files (images, js, etc.) stored here
/siteroot/index.php
/siteroot/.htaccess

测试重定向是否合理:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/public/$0 -f
RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]

如果前缀数量有限,则可以向正则表达式中添加另一个组:

RewriteRule ^(css|js|images|etc)/.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]

@丹·索塞多夫:还要注意凯文说的话。因为我的解决方案需要在重定向实际发生之前进行两次文件系统测试,所以这不是最经济高效的解决方案。
RewriteRule ^(css|js|images|etc)/.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]