这是一个正确设置后,没有“index.php”的固定链接设置页面
许多利用 Windows 搭建 WordPress 网站的用户会发现这样一个问题:在固定链接设置(wp-admin/options-permalink.php)的页面中,如果使用的是非默认固定链接,会被强制加上一个 index.php。为了网站的美观和 SEO 优化的效果,建议大家移除 index.php,并且方法将在下文提供。
如果网站支持UrlRewrite
新建一个 httpd.ini 或者在原有的 httpd.ini 中加入:
[ISAPI_Rewrite] RewriteRule ^/$ /index.php [L] RewriteRule /(.*) /index.php/$1 [L]
保存后,上传至 WordPress 程序所在的根目录,即可。
如果网站不支持UrlRewrite
这种情况处理起来会比起前面一种复杂一些,还需要能够自定义404错误页面。
新建一个 php 文件,文件名可以任意,比如404.php。在其中加入如下的代码:
<?php
header('HTTP/1.1 200 OK');
$ori_qs = $_SERVER['QUERY_STRING'];
$pattern = '/[^;]+;[^:]+:\/\/[^\/]+(\/[^\?]*)(?:\?(.*))?/i';
preg_match($pattern, $ori_qs, $matches);
$_SERVER['PATH_INFO'] = $matches[1] . '?' . $matches[2];
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
$query_args = explode('&', $matches[2]);
unset($_GET);
foreach ($query_args as $arg)
{
$the_arg = explode('=', $arg);
$_GET[$the_arg[0]] = $the_arg[1];
}
include('index.php');
?>
保存后,上传至 WordPress 程序所在的根目录,将自定义的404错误页面设置成为你保存的文件名,比如404.php。

