随身笔记
随身笔记

WordPress动态网页静态化的方法

之前的文章有写过为什么要将WordPress网址设置成伪静态,可以点击进入以下查看:
https://sdeno.com/wordpress为什么设置伪静态/
现在进入正题如何让WordPress动态网页静态化的方法:
使用IIS Rewrite静态化处理,适合PHP、ASP、ASP.NET程序
(1)isapi_rewrite.isapi_rewrite分精简(lite)和完全(full )版,精简版不支持对每个虚拟
主机站点进行重写,只能进行全局处理。
(2)打开iis,选择网站,右键菜单属性,添加过滤器,如图所示。

iiswei

(3)打开文件:选择“开始”-“程序”-“Helicon”-“ISAPI_Rewrite”-“httpd.ini”
命令。
(4)将RewriteRule /user/(\d+).htm /user.asp\?id=$1 [I,O]加人内容中。
(5)在浏览器地址栏输人:/user/l.htm,页面将指向/user.asp?id=1,

2)使用虚拟主机的ASP网站,需要使用404错误操作实现静态化
(1)下载404处理页面:404_Rewrite_GB2312.rar。
(2)解压后将Rewrite.asp, error.asp放在网站的根目录。
(3)设置网站自定义错误信息,如图所示。

iiswei2

(4)在error.asp里添加处理命令:
[code]call paraseurl(“/(\d+).htm”,”/user.asp?user=$1″)[/code]
(5)在需要静态化的实例user.asp页面中添加如下代码:

[code]<!– #include virtual=”/rewrite.asp” –>//引用文件
<%
response.write “<li>Para=”&session(“Para”)//变童是通过Session传递
response.write “<1i>request_(“”user””)=” & request_(“user”)
response.write “<1i>request_.querystring(“”user””)=” & request_.querystring(“user”)
%>[/code]

(6)在地址栏输人:/1.htm,实际调用/user.asp?user=l。

3)使用ASP.NET开发的网页程序,使用URLRewriter.dll实现静态化
(1)下载URLRewriter.rar,解压后放在/bin/目录下。
(2)将URLRewriter.rar加人工程引用。
(3)配置IIS站点,将扩展名为html指向处理程序aspnet_isapi.dll。即点击IIS站点-属
性-主目录-配置-添加,如图所示。

iiswei3

可执行文件和aspx处理相同,都是如下:
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
特别注意,一定不要选择检查文件是否存在。
(4)在web.config中添加配置内容,压缩包里有。

[code]<configsections>

<section name=”Rewriterconfig”

type=”urlrewriter.config.rewriterconfigserializersectionhandler,urlrewriter” />

</configsections>

<rewriterconfig>

<rules>

<rewriterrule>

<lookfor>~/(\d*).html</lookfor>

<sendto>~/user/default.aspx?link=$1</sendto>

</rewriterrule>

</rules>

</rewriterconfig>

<system.web>

<httphandlers>

<add verb=”*” path=”*.aspx”

type=”urlrewriter.rewriterfactoryhandler,urlrewriter” />

<add verb=”*” path=”.html”

type=”urlrewriter.rewriterfactoryhandler,urlrewriter” />

</httphandlers>[/code]

(5)在地址栏输人:http://localhost/l.html,指向http://localhost/user/default.aspx?link=1。

4)基于Apache HTTP Server静态化
Apache Web Server的配置(conf/httpd.conf)如下。
(1)在httpd.conf文件中查找LoadModule rewrite_module modules/mod_rewrite.so。
通常该行被注释,去掉“#”。如果没有就增加该行。
(2)加人如下代码:

[code]<IfModule mod_rewrite.c>
Rewriteengine on
RewriteRUle ^/([0-9]+).html$ /user.php?user=$1
</IfModule>[/code]
(3)如果网站使用通过虚拟主机来定义,请务必将代码添加到虚拟主机配置文件.htccess
中,否则可能无法使用。
(4)重启apache,重新载人配置。
(5)在地址栏输人:http://localhost/l.html,实际指向http://localhost/user.php?user=1。

之前也写过许多相关的文章是关于修改wordpress固定链接的:
https://sdeno.com/默认wordpress短链接自动跳转自定义固定链接/

随身笔记

WordPress动态网页静态化的方法
之前的文章有写过为什么要将WordPress网址设置成伪静态,可以点击进入以下查看: https://sdeno.com/wordpress为什么设置伪静态/ 现在进入正题如何让WordPress动态网页静态化的方法: …
扫描二维码继续阅读
2013-03-01