2011-12-23 58 views
2

這是我的.htaccess文件:如何獲得RewriteCond中的本地路徑?

RewriteEngine On 

RewriteBase /projs/CodeIgniterTest 

RewriteCond %{REQUEST_URI} !^/projs/CodeIgniterTest/index.php 
RewriteRule ^(.*)$ index.php/$0 

RewriteRule工作正常,但我不能讓RewriteCond線與本地路徑工作。我想這個工作:

RewriteCond %{REQUEST_URI} !^index.php 

但可惜%{REQUEST_URI}並不那麼在意RewriteBase線,並使用完整路徑。有什麼方法可以達到我想要的效果嗎?我不想每次更改項目路徑時都必須編輯.htaccess文件。

回答

3
RewriteRule ^index.php - [L] 
RewriteRule ^(.*)$ index.php/$0 

或者只是

RewriteCond $0 !^index.php 
RewriteRule ^(.*)$ index.php/$0 
+0

'的RewriteCond $ 0!^ index.php'工作就像一個魅力!但是,你能解釋'$ 0'部分嗎?在RewriteCond文檔中我沒有看到任何類似的東西 – Hubro 2011-12-23 17:17:02

+1

Apache在重寫規則中匹配regex,在執行rewritecond規則之前。 RewriteCond可以在TestString中使用$ 0..9。所以在你的情況下$ 0包含相對於你的rewritebase的路徑。 (它在http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond的第一個bulletpoint) – Gerben 2011-12-23 17:33:26

+0

很好解釋,謝謝! – Hubro 2011-12-23 20:10:48