2012-11-19 12 views
0

我想使用htaccess檢查URL。開發者可能想要運行特殊文件 - specialfile.php。我使用htaccess的:使用htaccess檢查URL並停止處理

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} /specialfile\.php$ 
RewriteRule .* [L] #don't change adress 
RewriteRule ^$ public/index.html [NC,L] 
RewriteRule (.*) public/$1 [NC,L] 

我的想法是:如果的RewriteCond%{REQUEST_URI}比的htaccess應該使用重寫規則/specialfile.php$真實* [L] - 這應該意味着specialfile.php將運行並這一切。但它不起作用,因爲它運行下一條規則:重寫規則(。*)public/$ 1 [NC,L]。

回答

0

我認爲你使用的是不正確的RewriteCond。條件僅影響下面的下一個RewriteRule

結帳the example on the Apache Homepage。由於你的第二個RewriteRule是評估,我認爲你的條件是不正確的。爲了獲得更多有關重寫的信息,你應該增加日誌級別。這is also documented here

你的第二條規則^$只匹配一個空的請求btw。這就是爲什麼它可能不像你期望的那樣工作。

+0

這對我很有幫助。謝謝 –