2017-07-17 159 views
1

我有以下.htaccess服務的一切index.php,並防止.txt顯示靜態文件。htaccess重寫多個條件

我想添加只需一個附加規則:重定向example.com/reexample.com/re.php。這個怎麼做?

這失敗了,我不知道爲什麼:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^re$ re.php  //fail: style.css won't be accessible anymore, leading to broken website 
RewriteRule ^(.*)$ index.php [QSA,L] 
RewriteRule \.txt$ index.php [L] 
+0

嘿@basj檢查這個問題:[here](https://stackoverflow.com/questions/17048796/htaccess-add-php-to-everything-without-an-extension-already) - 類似問題,回答可能會幫助你。 – Lag

+0

@thickguru我花了最後30分鐘,但仍然無法使它工作。當我在任何地方插入'RewriteRule^re $ re.php [L]'時,它會打破一切,並使style.css被破壞。 – Basj

+1

RewriteCond僅影響直接跟隨的RewriteRule。所以,只要在這些之後直接插入一條不同的規則,就可以從根本上改變整個事情。根據您最新的評論,您使用的[L]標誌在您的問題中顯示的代碼中缺失。 – CBroe

回答

1

正如評論指出的@CBroe,的RewriteCond隻影響直接重寫規則如下,所以這是解決方案:

RewriteEngine On 

RewriteRule ^re$ re.php [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php [QSA,L] 

RewriteRule \.txt$ index.php [L]