李环宇 發表於 2023-9-21 00:00:00

wordpress在IIS下伪静态后子目录无法访问的解决方法

<p>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>众所周知,wordpress是基于php开发,在apache服务下运行是最优秀的。但是,国内仍然有很多主机上不能提供apache服务器,大多都是IIS环境。因此,导致wp在IIS环境下,出现很多问题,解决起来也比较麻烦。UISEO优化网也不小心使用了IIS。因此,在遇到的关于IIS环境造成的一系列问题,记录下来,帮助有同样痛苦的站长共同分享。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>本篇主要是关于IIS伪静态成功后造成的子目录和其他一些根目录的文件不能正常访问的问题。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>近几日想给博客加上一些别的页面,自然要用到子目录。没想到访问所有非WP-开头的子目录内容都转到404页面去了。看样子WP还真有的高深莫测,令我丈二和尚摸不着头脑啊,后找了不少资料才基本解决此问题,方法是修改伪静态规则文件httpd.ini: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>下载或者在线编辑httpd.ini文件,在原来规则中增加一条代码RewriteRule /tool/(.*) /tool/$1 ,增加后完整规则如下(/tool/是二级目录名,具体名称是什么就写什么,注意是双斜杠): </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>编辑httpd.ini规则: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
 <br>
# Defend your computer from some worm attacks <br>
#RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* .  <br>
# 3600 = 1 hour <br>
CacheClockRate 3600 <br>
RepeatLimit 32 <br>
# Protect httpd.ini and httpd.parse.errors files <br>
# from accessing through HTTP <br>
# Rules to ensure that normal content gets through <br>
RewriteRule /favicon.ico /favicon.ico  <br>
RewriteRule /sitemap.xml /sitemap.xml  <br>
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml  <br>
RewriteRule /sitemap.html /sitemap.html  <br>
# For file-based wordpress content (i.e. theme), admin, etc. <br>
RewriteRule /wp-(.*) /wp-$1  <br>
# For normal wordpress content, via index.php <br>
RewriteRule ^/$ /index.php  <br>
RewriteRule /(.*) /index.php/$1  </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>上面的内容是配置伪静态,以下是设置子目录访问配置代码 </strong><br><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果需要某个子目录(比如</span>UISEO优化网<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>需要增加pr子目录),则在# Rules to ensure that normal content gets through行下增加如下内容: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
RewriteRule /pr/(.*) /pr/$1  </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果有多个子目录的话,也是可以的,设置几条这样的规则就行了。如: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
RewriteRule /文件夹名1/(.*) /文件夹名1/$1  <br>
RewriteRule /文件夹名2/(.*) /文件夹名2/$1  <br>
RewriteRule /文件夹名3/(.*) /文件夹名3/$1  </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>就这样,基本上可以解决此问题。或许还有更好的方法,继续摸索中……也欢迎大家共享。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果是想访问根目录下的其他文件,比如验证文件html。则参考</strong><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
RewriteRule /sitemap.xml /sitemap.xml  </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>只需将相应名称换成要访问的即可。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>对于具体的语法,想更深入了解的,可以百度,也可以找本人。随时为大家无私奉献!</span></p>
頁: [1]
查看完整版本: wordpress在IIS下伪静态后子目录无法访问的解决方法