解决windows主机下wordpress伪静态的方法

  • A+
所属分类:网站建设

第一步、新建一个记事本,在里面写入下面代码保存为txt格式,重新命名为404.php,上传到网站根目录

代码:

<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>
第二步、到你的虚拟主机控制面板,设置404自定义错误指向404.php

第三步、进入WordPress管理后台,点击设置(Options),点击固定链接(Permalinks)

以上的修改只能实现网址中只含有英文字符的伪静态,如果你要同时实现网址中包含中文字符的伪静态,请将上面的代码换成如下的代码:

<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_SERVER['PATH_INFO'] = iconv("GBK//IGNORE", "UTF-8//IGNORE", $_SERVER['REQUEST_URI']);
include('index.php');
?>

附录:设置静态链接常用参数

%year% 
The year of the post, four digits, for example 2004
%monthnum% 
Month of the year, for example 05
%day% 
Day of the month, for example 28
%hour% 
Hour of the day, for example 15
%minute% 
Minute of the hour, for example 43
%second% 
Second of the minute, for example 33
%postname% 
A sanitized version of the title of the post (post slug field on Edit Post/Page panel). So “This Is A Great Post!” becomes this-is-a-great-post in the URI (see Using only %postname%). Starting Permalinks with %postname% is strongly not recommended for performance reasons.. *** Note - this has been changed and is ok to do since ver. 2.0
%post_id% 
The unique ID # of the post, for example 423
%category% 
A sanitized version of the category name (category slug field on New/Edit Category panel). Nested sub-categories appear as nested directories in the URI. Starting Permalinks with %category% is strongly not recommended for performance reasons.
%tag% 
A sanitized version of the tag name (tag slug field on New/Edit Tag panel). Starting Permalinks with %tag% is strongly not recommended for performance reasons.
%author% 
A sanitized version of the author name

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  1   博主  0   引用   1

    • avatar 陌凡 0

      陌凡,不错学习

    • 来自外部的引用: 1

      • 如何撰写robots.txt