首页 > 网站建设 > WordPress在Windows主机下实现伪静态配置的方法

WordPress在Windows主机下实现伪静态配置的方法

十二月 12th, 2013 关键字:

大部分网友在使用wordpress时,选择的是windows主机,我们知道windows在默认状态下是不支持伪静态的,那么如何使我们的程序实现伪静态呢,这里有个简单的方法。

1、新建一个文本文档,复制下面代码到文档里,然后把文档保存为404.php。将404.php上传至网站根目录。代码如下:
<?php

// 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);

?>
2、进入主机设置,主机后台基本都有自定义出错页中的404出错设置,选择404.php,如图:

404chucuophp

3、网站设置,进入后台,点击设置,选固定链接设置,在常用设置线选择适合你的一种。本博客选择的是自定义结构,如图:

wpchangyongshezhi

 

固定地址:WordPress在Windows主机下实现伪静态配置的方法 | https://www.cnjoel.com/796.html