wordpress定义blog的固定连接分为三个档次
默认的链接如下
http://example.com/?p=N
使用mod_rewrite或lighttpd可以生成更好看的链接地址(查看 漂亮的链接),有各种个样的链接格式,最常见、最通用的格式如下
http://example.com/category/post-name/ or http://example.com/year/month/day/post-name.html
PATHINFO类型的链接地址和mod_rewrite类型的地址看起来很像,唯一的区别是在前面多了/index.php,如下:
http://example.com/index.php/yyyy/mm/dd/post-name/
PATHINFO类型的连接无需复杂的操作就可以实现,在wordpress后台面板就可以设置,要想实现静态地址,在连接的最后添加.html即可。但是/index.php是不能去掉的,去掉就不河蟹了。
漂亮的连接是指自定义的不带index.php的固定连接,也就是把PATHINFO类型的链接地址的index.php去掉,但是,如果我们直接把index.php去掉,就会出现打开页面错误。解决方法很简单,自定404页面就可以了。把你的404页面代码改为一下代码就可以了。
// This is the default file for the site. Usually index.php
$default
=
'index.php'
;
// The name of this file.
// Set this value for the URL in Custom Error Properties of your website in IIS.
// Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
// 404 & 404;2 & 404;3 > URL (Requires a '/' prefix in IIS).
$thisfile
=
'404-handler.php'
;
$_SERVER
[
'ORIG_PATH_TRANSLATED'
] =
str_replace
(
$thisfile
,
$default
,
$_SERVER
[
'ORIG_PATH_TRANSLATED'
]);
$_SERVER
[
'SCRIPT_FILENAME'
] =
str_replace
(
$thisfile
,
$default
,
$_SERVER
[
'SCRIPT_FILENAME'
]);
$_SERVER
[
'ORIG_PATH_INFO'
] =
str_replace
(
$thisfile
,
$default
,
$_SERVER
[
'ORIG_PATH_INFO'
]);
$_SERVER
[
'SCRIPT_NAME'
] =
str_replace
(
$thisfile
,
$default
,
$_SERVER
[
'SCRIPT_NAME'
]);
$_SERVER
[
'PHP_SELF'
] =
str_replace
(
$thisfile
,
$default
,
$_SERVER
[
'PHP_SELF'
]);
$_SERVER
[
'PATH_INFO'
] = false;
$qs
=&
$_SERVER
[
'QUERY_STRING'
];
$ru
=&
$_SERVER
[
'REQUEST_URI'
];
$pos
=
strrpos
(
$qs
,
'://'
);
$pos
=
strpos
(
$qs
,
'/'
,
$pos
+ 4);
$_SERVER
[
'URL'
] =
$ru
=
substr
(
$qs
,
$pos
);
$qs
= trim(
stristr
(
$ru
,
'?'
),
'?'
);
// Required for WordPress 2.8+
$_SERVER
[
'HTTP_X_ORIGINAL_URL'
] =
$ru
;
// Fix GET vars
foreach
(
$_GET
as
$var
=>
$val
) {
if
(
substr
(
$var
, 0, 3) ==
'404'
) {
if
(
strstr
(
$var
,
'?'
) ) {
$newvar
=
substr
(
$var
,
strpos
(
$var
,
'?'
) + 1);
$_GET
[
$newvar
] =
$val
;
}
unset(
$_GET
[
$var
]);
}
break
;
}
include
(
$default
);
?>
你可能感兴趣的:(blog)