使用win主机根目录上建立wordpress网站,同时又在子目录(二级目录)建立一个论坛程序(链接形式如:www.jaaai.com/bbs
)
发现了一个问题:无法访问子目录了,发现只要是非wp-开头的子目录文件夹,比如文件夹名为bbs的这个子目录,通过https://www.jaaai.com/bbs
访问,都会跳转到wordpress的404错误页面。
经过调试,发现是wordpress使用了伪静态造成了,我把伪静态httpd.ini文件删除掉,二级目录就可以访问了。但是这样,wordpress的伪静态要如何实现?
其实只需要给子目录(二级目录)增加一条规则就行了!
编辑httpd.ini
规则如下,通过使用安装rewrite组件,编辑httpd.ini规则来设置wordpress伪静态,不懂的设置的可以看文章:win主机下WordPress博客伪静态设置方法解决中文标签无法打开链接
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
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]</code></pre>
上面的代码是实现wordpress伪静态的httpd.ini规则,现在给子目录(二级目录)在原来的规则中单独添加一条规则,比如子目录“bbs”我们可以这样写:
<pre class="pure-highlightjs"><code class="null">RewriteRule /bbs(.*) /bbs$1 [L]
RewriteRule /bbs/(.*) /bbs/$1 [L]
上面这条规则的意思就是访问“/bbs/”都会转到“bbs”这个子目录,也就是说访问https://www.jaaai.com/bbs/
时就转到服务器根目录下的bbs文件夹!
这里要注意的是子目录访问地址:“http://你的域名/目录/ ” 这里目录名是两个斜杠的!
至于这条规则放置的位置,不能放到最后面,最好放在# For normal wordpress content, via index.php
这一行的下面
完整代码如:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
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 /bbs(.*) /bbs$1 [L]
RewriteRule /bbs/(.*) /bbs/$1 [L]
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]
当然了,如果你有多个子目录的话,可以多设置几条这样的规则,也就是把规则里的“bbs”换成相应的文件夹名称就可以拉!
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
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 /文件夹名称1(.*) /文件夹名称1$1 [L]
RewriteRule /文件夹名称1/(.*) /文件夹名称1/$1 [L]
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]
非特殊说明,本博所有文章均为博主原创。
如若转载,请注明出处:https://www.jaaai.com/58.html
共有 0 条评论