最新消息:

WordPress用404页面去掉链接index.php方法

软件技术 3698浏览

Windows的主机都是用IIS做为网站服务的,但是在IIS的环境下安装Wordpress后,固定链接里的链接都会多一个index.php,这对搜索引擎来说并不利于收录的,Linux主机的apache是没有这个问题的。所以要去掉这个index.php可以采用404自定义错误页面的方法,在404错误页面添加如下内容即可。(注意去掉< ?php之间的空格) < ?php $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页面去掉链接index.php方法