6

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

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

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

4

1 回答 1

8

我在这里找到了一些参考:http ://httpd.apache.org/docs/current/mod/mod_rewrite.html

RewriteEngine On启用重写模块。

RewriteRule ^index\.php$ - [L]确保 ifindex.php被调用,没有其他规则被执行。这-是为了确保不会发生重写,并且[L]标志指示不应执行其他规则。

RewriteCond %{REQUEST_FILENAME} !-f将条件添加到以下重写规则。此条件表示请求的文件名不是( !) 现有文件。

RewriteCond %{REQUEST_FILENAME} !-d是相同的,但对于现有目录。

RewriteRule . /index.php [L]表示所有内容( .) 都应重写为/index.php,并且这是执行 ( [L]) 的最后一条规则。

于 2013-04-10T17:28:07.543 回答