再次谈windows主机下wordpress实现伪静态

大家都知道,linux下wordpress实现伪静态很简单,只需要在后台-设置-固定链接里面设置一下即可,这里,我来说说win主机如何设置伪静态吧!

我之前,也搜索过很多方法,由于本站使用的是win主机,所以不支持直接设置搞定,不过还是可以弄伪静态的!下面我来介绍方法,首先我们需要写一个php文件,代码如下

<?php
$default = 'index.php';
$thisfile = '404.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'];
$qs = mb_convert_encoding("$qs","UTF-8","GBK"); //转换编码以支持中文URL
$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);
?>

然后保存命名为404.php【本php文件下载地址:http://bbs.sdtclass.com/thread-31-1-1.html

我们把这个php文件上传到网站根目录,也就是index.php同一个目录下,然后进去自己网站后台,自定义出错页面设置下404的出错页为404.php,这里完成了一个步骤

然后,我们写一个规则文件,内容如下:

ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# 中文tag解决
RewriteRule /tag/(.*) /index.php?tag=$1
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /robots.txt  /robots.txt [L]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

以上内容保存为httpd.ini,然后上传到自己的网站根目录,也就是404.php的目录

这个时候,我们进入后台-设置-固定链接进行设置,选择一个你自己需要的伪静态方式即可!记得标签的地方填写个tags哦!下面附带我的规则文件给大家

 

[ISAPI_Rewrite]
RewriteCond Host: (.+)
RewriteCond Referer: (?!http://\1.*).*【防盗链开始】
RewriteCond Referer: (?!http://(.*)(\.baidu\.com|\.google\.com|\.google\.cn|\.g\.cn|\.gougou\.com|\.soso\.com|\.sogou\.com|\.youdao\.com|\.bing\.com|\.yahoo\.com|\.yahoo\.cn|\.eojoo\.com)).*【禁止搜索引擎引用图片】
RewriteRule .*\.(?:gif|jpg|jpeg|png|bmp|rar|zip|apk|sis|sisx) /g [I,O,N]【这里是防止盗链的文件后缀名,自己修改】
RewriteRule /post/tag/(.*) /index\.php\?tag=$1
RewriteRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /(about|link|tags|sitemap) /index\.php\?pagename=$1
RewriteRule /post/category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed\.php\?category_name=$1&feed=$2
RewriteRule /post/category/?(.*) /index\.php\?category_name=$1
RewriteRule /author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed\.php\?author_name=$1&feed=$2
RewriteRule /author/?(.*) /index\.php\?author_name=$1
RewriteRule /feed /index\.php/\?feed=rss2
RewriteRule /rss.xml /index\.php/\?feed=rss2
RewriteRule /comments/feed /index\.php/\?feed=comments-rss2
RewriteRule /([0-9]+)/?([0-9]+)?/?$ /index\.php\?p=$1&page=$2
RewriteRule /post/([0-9]+)/?([0-9]+)?/?$ /index\.php\?p=$1&page=$2
RewriteRule /post/([0-9]+).html /index\.php\?p=$1 [I]
RewriteRule /page/(.*)/?s=(.*) /index\.php\?s=$2&paged=$1
RewriteRule /page/(.*) /index\.php\?paged=$1
RewriteRule /post/date/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ /index\.php\?year=$1&monthnum=$2&day=$3&name=$4&page=$5
RewriteRule /post/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index\.php\?year=$1&monthnum=$2&day=$3&page=$4
RewriteRule /post/date/([0-9]{4})/([0-9]{1,2})/?$ /index\.php\?year=$1&monthnum=$2&page=$3
RewriteRule /post/([0-9]+).html/(feed|rdf|rss|rss2|atom) /index\.php\?feed=rss2&p=$1
RewriteRule /post/([0-9]+).html/trackback /wp-trackback\.php\?p=$1
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
RewriteRule /robots.txt /robots.txt [L]【允许robots.txt等文件被访问】
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /favicon.ico /favicon.ico [L]

CacheClockRate 3600
RepeatLimit 32
RewriteRule /tag/(.*)/ /index\.php\?tag=$1

注意红色文字不要写进去,自己修改下缩进,我这是主题原因这样的,其实是靠边的没有缩进

好!大致说道这里咯!反正很简单【httpd.ini文件下载地址:http://bbs.sdtclass.com/thread-31-1-1.html

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

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

  1. avatar snowinmay 3

    学习一下,尽管我的也是win主机,但是我已经不想折腾啦!

    • avatar yumanutong 5

      @snowinmay 额,你没弄伪静态?

  2. avatar 分享盒子 1

    小草 百度联盟 你备案没有呢?

    • avatar yumanutong 5

      @分享盒子 额,你没有看页脚啊,粤ICP备…..

  3. avatar 第四个李智 4

    那天 xampp 伪静态纠纠我很久。

  4. avatar 跑步机价格 1

    看的头都晕了哦,呵呵

    • avatar yumanutong 5

      @跑步机价格 额,复制黏贴总会吧,而且我有附带下载…

评论加载中...

来自外部的引用: 1

  • SDT技术网文章索引-四月份 | yumanutong blog

发表评论

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

图片 表情