由于父文件夹中的.htaccess,子目录中的Wordpress站点无法正确重定向到帖子

由于父文件夹中的.htaccess,子目录中的Wordpress站点无法正确重定向到帖子,wordpress,apache,.htaccess,Wordpress,Apache,.htaccess,我有个奇怪的案子。。。我有一个wordpress站点,它安装在另一个站点的文件夹(示例)中。之所以如此,是因为wordpress站点属于一个驻留的域(例如.net) 所以!在我的主站点的文件夹中,我有这个.htaccess ## rules for error documents ErrorDocument 400 /400.php ErrorDocument 401 /401.php ErrorDocument 403 /403.php ErrorDocument 404 /404.php E

我有个奇怪的案子。。。我有一个wordpress站点,它安装在另一个站点的文件夹(示例)中。之所以如此,是因为wordpress站点属于一个驻留的域(例如.net)

所以!在我的主站点的文件夹中,我有这个.htaccess

## rules for error documents
ErrorDocument 400 /400.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

<IfModule mod_rewrite.c>
RewriteEngine On

## no trailing slash policy
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

## rewrite html pages if there is a present php equivalent
RewriteRule ^(.*)\.html$ $1.php?%{QUERY_STRING} [L]

## if 'examle' is required, take us to the example.net domain
RewriteRule ^example - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.net$ [NC]
RewriteRule ^(.*)$ example/$1 [L]
</IfModule>
##错误文档规则
ErrorDocument 400/400.php
ErrorDocument 401/401.php
ErrorDocument 403/403.php
ErrorDocument 404/404.php
ErrorDocument 500/500.php
重新启动发动机
##无尾随斜杠策略
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)/$/$1[L,R=301]
##重写html页面,如果有当前的php等价物
重写规则^(.*)\.html$$1.php?%{QUERY\u STRING}[L]
##如果需要“examle”,请转到example.net域
重写规则^example-[L]
重写cond%{HTTP_HOST}^(www\)?示例\.net$[NC]
重写规则^(.*)$example/$1[L]
wordpress站点的.htaccess是默认的:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
我可以成功地打开Wordpress站点的主页,但是,当我尝试转到它的一些页面/帖子时,我看到了错误

页面未正确重定向


我使用的是Apache2.4,我解决了这个问题。结果证明(我不知道)没有尾随斜杠策略破坏Wordpress。它严格要求后面的斜杠是保留的

解决方案是以这种方式编写无尾随斜杠策略,因此如果您访问wordpress站点,它将不会被执行

就我而言,我将规则更改为:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example\.net$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
</IfModule>

重新启动发动机
重写cond%{HTTP_HOST}^(www\)?示例\.net$[NC]
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)/$/$1[L,R=301]

我解决了这个问题。结果证明(我不知道)没有尾随斜杠策略破坏Wordpress。它严格要求后面的斜杠是保留的

解决方案是以这种方式编写无尾随斜杠策略,因此如果您访问wordpress站点,它将不会被执行

就我而言,我将规则更改为:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example\.net$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
</IfModule>

重新启动发动机
重写cond%{HTTP_HOST}^(www\)?示例\.net$[NC]
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)/$/$1[L,R=301]