关于WordPress重写规则的说明

时间:2013-04-10 17:00:03

标签: wordpress .htaccess

我在WordPress网站的.htaccess中找到了这些重写规则:

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

我知道这基本上都是指index.php。但它是如何工作的?什么规则做什么?

1 个答案:

答案 0 :(得分: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] )。