2013-04-10 43 views
6

我發現這些重寫規則,在我的WordPress網站的.htaccess:說明在WordPress的重寫規則

RewriteEngine On 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

我知道,這基本上是指一切的index.php。但它是如何工作的?什麼規則做什麼?

+0

我有同樣的問題(http://stackoverflow.com/q/35303598/2983568),並在這裏發現了詳細的解釋:http://glennmessersmith.com/pages/wphtaccess.html – supafly 2016-02-10 08:04:03

回答

8

我發現這裏一些參考:http://httpd.apache.org/docs/current/mod/mod_rewrite.html

RewriteEngine On使重寫模塊。

RewriteRule ^index\.php$ - [L]可以確保在index.php被調用時,沒有其他規則執行。 -是爲了確保不會發生重寫,並且[L]標誌指示不應該執行其他規則。

RewriteCond %{REQUEST_FILENAME} !-f爲以下重寫規則添加條件。此條件表示請求的文件名是而不是!)現有的文件。

RewriteCond %{REQUEST_FILENAME} !-d是相同的,但對於現有的目錄。

RewriteRule . /index.php [L]一切.)應該重寫/index.php,並認爲這是執行([L])的最後一個規則。