重定向到现有文件/文件夹(如果它存在于特定目录中)或转到index.php

时间:2011-11-13 19:44:08

标签: apache mod-rewrite url-rewriting

我有一个文件夹App\ressources,其中包含所有图片,网站的javascript库。

我要做的是重定向到现有的image / js或转到将处理请求并获取当前模块/控制器/操作的index.php文件。

所以我做了这个:

RewriteEngine On

RewriteCond App/ressources/$1 -d [OR]
RewriteCond App/ressources/$1 -f
RewriteRule ^(.+)$ App/ressources/$1 [L]

RewriteRule ^(.*)$ index.php [QSA]

这并不困难,但是“贬值”是不可能的。

1 个答案:

答案 0 :(得分:1)

我已经要求same question,但我没有得到答案。

以下是我的解决方法:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) App/ressources/$1 [DPI]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule App/ressources/(.*) $1 [DPI]

RewriteCond %{REQUEST_FILENAME} !-f     # missing line, see comments
RewriteRule (.*) index.php [L,QSA,DPI]

基本上我们将所有内容(不存在的文件)重定向到App / ressources,如果它仍然不存在,我们将其重定向回/ root目录。然后我们将其重定向到index.php。

  1. 如果文件不存在,请重定向到App / resources /
  2. 如果文件仍然不存在,请重定向回root /
  3. 如果文件仍然不存在,请重定向到index.php