存档

文章标签 ‘伪静态’

Win服务器下设置WordPress固定链接伪静态

2010年1月29日 没有评论

以下就是怎么实现的:
只要主机支持自定义404页面,无需安装插件,就能让Win主机像Linux 那样,方便使用WordPress的固定链接为静态化地址格式。

<?php
header("HTTP/1.1 200 OK");
$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');
?>

设置固定链接(Permalink)伪静态步骤:
1. 将以上代码保存为 404.php,并上传至主机根目录。
2. 设置 404 自定义错误页为 404.php。
3. 进入 WordPress 控制面板,设置(Options)- 固定链接(Permalinks),选择固定链接格式。

分类: WP相关 标签: , ,

Windows+apache+php5 开启URL rewrite方法

2009年12月6日 没有评论

运行效果
139_96834_42162c646c897da

我是在windowsXP下安装的apache2.2.4 和php5.2,在apache下不用安装ReWrite ISAPI包,只有在IIS下才用。
方法如下:
编辑apache的配置文件httpd.conf
第一步:找到
<Directory “F:\webhosts”>  其中”F:\webhosts”是你自己设置的虚拟目录,根据你自己的设置会有不同
#
# Possible values for the Options directive are “None”, “All”,
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that “MultiViews” must be named *explicitly* — “Options All”
# doesn’t give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride None        ***就把这个改成AllowOverride All***

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>

把其中的AllowOverride None 改成AllowOverride All

第二步:
搜索 LoadModule rewrite_module modules/mod_rewrite.so (Apache2是这个)
去掉前面的#
第三步:
重启 apache
第四步:
直接去后台 营销推广–>SEO设置–>商店页面启用伪静态URL  打上勾 保存。OK。

分类: 建站相关 标签:

使用PHP模拟 URL Rewrite

2009年12月6日 没有评论
/***********************************************************
* Document Type: Classes
* Update: 2007/03/28
* Author: Akon
* Remark: 模拟 URL Rewrite
***********************************************************/

class URLRewrite {

var $_query_string;

/**
* 构造函数
*
*/

function URLRewrite() {
$this-%26gt;_query_string = str_replace(.html, , $_SERVER[%26quot;QUERY_STRING%26quot;]);
}

/**
* 返回模拟 Rewirte 形态页面传递字符串
*
*/

function GetRewriteString() {
if (!strpos($this-%26gt;_query_string, %26amp;)) return $this-%26gt;_query_string;
$URLArray = explode(%26amp;, $this-%26gt;_query_string);
for ($i=0; $i%26lt;count($URLArray); $i++) {
if (strpos($URLArray[$i], =)+1 != strlen($URLArray[$i]))
$ParaArray[] = str_replace(=, /, $URLArray[$i]);
}
return implode(/, $ParaArray);
}

/**
* 返回模拟 Rewirte 形态的 URL 地址
*
*/

function GetRewriteUrl() {
return $_SERVER['PHP_SELF'] . ? . $this-%26gt;GetRewriteString() . .html;
}

/**
* 返回原始形态页面传递字符串
*
*/

function GetOriginalString() {
$URLArray = explode(/, $this-%26gt;GetRewriteString($this-%26gt;_query_string));
for ($i=0; $i%26lt;count($URLArray); $i=$i+2) {
if ($URLArray[$i] %26amp;%26amp; $URLArray[$i+1])
$ParaArray[] = $URLArray[$i] . = . $URLArray[$i+1];
}
return implode(%26amp;, $ParaArray);
}

/**
* 返回原始形态的 URL 地址
*
*/

function GetOriginalUrl() {
return $_SERVER['PHP_SELF'] . ? . $this-%26gt;GetOriginalString();
}

/**
* 将解析的参数写入到 $_GET 预定义变量
*
*/

function ParseUrl() {
$URLArray = explode(/, $this-%26gt;GetRewriteString());
$_GET = ;
for ($i=0; $i%26lt;count($URLArray); $i=$i+2) {
$_GET[$URLArray[$i]] = $URLArray[$i+1];
}
$_SERVER[%26quot;QUERY_STRING%26quot;] = $this-%26gt;GetOriginalString();
$_SERVER[%26quot;R_QUERY_STRING%26quot;] = $this-%26gt;GetRewriteString();
}
}

分类: 编程开发 标签: ,