2011-10-24 61 views
2

這裏是我的代碼:mod_rewrite的 - 路徑添加到REQUEST_FILENAME可變

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

我想要表達:

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

結果示例S:

  • /style.css = /application/public/style.css
  • /gfx/logo.png = /application/public/gfx/logo.png
  • 的index.php =/index.php文件
  • /歡迎= /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] 

(對不起,我的英語)

+0

我想我還需要使用%{REQUEST_URI},但我不知道如何。 – Peter

回答

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]