wordpress子目录伪静态的配置方法

发布时间:2020-05-17编辑:脚本学堂
本文介绍下,在wordpress中为网站子目录配置伪静态的方法,感兴趣的朋友参考学习下。

本节内容:
wordpress子目录伪静态

Win主机用wordpress,并使用伪静态后,导致站点根目录的一些与wordpress无关的文件也无法访问,都重定向到404页面。

Win主机对wordpress支持不是很完美。

在用wordpress时通常要用到的就是伪静态,Win主机下如果设置伪静态需要提供Rewrite组件支持,还需要提供一份伪静态httpd.ini规则文件。、

例如,httpd.ini规则文件:
 

复制代码 代码示例:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /software-files/(.*) /software-files/$1 [L]
RewriteRule /images/(.*) /images/$1 [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]

上传FTP至WIN主机下,由主机加载规则文件后,之前的链接可以继续访问,还可设置固定链接的优化,但是原来可以访问的子目录,也就是二级目录不能访问了,重定向至404页面,此时可通过重新配置httpd.ini规则文件,假如我的子目录名称为yachun,新增一条伪静态规则如下:
 

复制代码 代码示例:
RewriteRule /yachun/(.*) /yachun/$1 [L]
 

也可以根据多子目录需求增加多条规则,规则同上。
配置完成,经测试链接可能成功,但也可能依旧重定向404页面。

可能的问题:
重定向的规则文件的位置不对所造成的问题,即新增的静态规则不要放在最后面,应该置放在:
 

复制代码 代码示例:
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]
 

的前面,上传FTP,服务器加载过后,测试成功!!

代码:
 

复制代码 代码示例:
# For normal wordpress content, via index.php
RewriteRule /yachun/(.*) /yachun/$1 [L]
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]