mod_rewrite-除静态文件夹外全部索引 [英] mod_rewrite - all to index except static folder
本文介绍了mod_rewrite-除静态文件夹外全部索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试,但是找不到解决方案,这确实很容易.我有规则
I've been trying and trying and can't find the solution, which surely is pretty easy. I have rule
RewriteEngine on
RewriteRule (.*) index.php [L]
因此它将所有URL重定向到index.php,现在我希望所有文件都希望将其重定向到静态文件夹中,因此不会重定向诸如domain.com/static/...之类的URL.我尝试了例如:
So it redirects all urls to index.php, now I want all files expect this in static folder to be redirected, so urls like domain.com/static/... would not be redirected. I tried for example:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^static$
RewriteRule (.*) index.php [L]
或
RewriteEngine on
RewriteRule static/(.*) static/$1 [L]
RewriteRule (.*) index.php [L]
还有其他一些变化,但似乎无济于事...
And some other variations but nothing seems to work...
推荐答案
在正则表达式中,使用负数预读
In your regex, use a negative look-ahead
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(?!/static/).+ [NC]
RewriteRule (.*) index.php [L]
这篇关于mod_rewrite-除静态文件夹外全部索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文