mod_rewrite - 添加REQUEST_FILENAME变量的路径

时间:2011-10-24 16:42:37

标签: php apache mod-rewrite

这是我的代码:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond application/public/%{REQUEST_FILENAME} -f 
RewriteRule (.*) application/public/$1 [L]

我想表达:

  • 如果文件{REQUEST_FILENAME} 不存在,如果文件application/public/%{REQUEST_FILENAME} 存在,请重写

示例结果:

  • /style.css = /application/public/style.css
  • /gfx/logo.png = /application/public/gfx/logo.png
  • /index.php = /index.php
  • / Welcome = /index.php?input=Welcome(正在运作)

这个表达式的正确代码是什么?我想我需要换行:

RewriteCond application/public/%{REQUEST_FILENAME} -f 

但我没有血腥的想法......

完整.htaccess列表:

RewriteEngine on

RewriteRule style,(.+).css tmp/merged/css,$1 [L,QSA]
RewriteRule script,(.+).js tmp/merged/js,$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond application/public/%{REQUEST_FILENAME} -f 
RewriteRule (.*) application/public/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) index.php?input=$1 [L,QSA]

(对不起我的英文)

1 个答案:

答案 0 :(得分:0)

我发现了一个小的解决方法,但它并不是优雅的解决方案:(

RewriteEngine on

# Access to files in ./application/public
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) application/public/$1 [DPI]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule application/public/(.*) $1 [DPI]

# Main rewrite
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) index.php?input=$1 [L,QSA,DPI]