Php Wordpress%postname%permalinks打破静态主页(301)
所以我现在有一段时间有这个问题,我似乎找不到合适的解决方案 每当我启用%postname%permalinks时,我的静态主页Php Wordpress%postname%permalinks打破静态主页(301),php,wordpress,.htaccess,permalinks,Php,Wordpress,.htaccess,Permalinks,所以我现在有一段时间有这个问题,我似乎找不到合适的解决方案 每当我启用%postname%permalinks时,我的静态主页https://example.com/xy停止工作并发送301“站点未正确重定向”错误,而站点上的任何其他帖子或页面正确重定向,例如https://example.com/xy/about-us有效 如果我恢复到普通链接,我没有问题。 我注意到的两件事是,如果我在主页末尾添加“index.php”,它将再次加载,例如https://example.com/xy/inde
https://example.com/xy
停止工作并发送301“站点未正确重定向”错误,而站点上的任何其他帖子或页面正确重定向,例如https://example.com/xy/about-us
有效
如果我恢复到普通链接,我没有问题。
我注意到的两件事是,如果我在主页末尾添加“index.php”,它将再次加载,例如https://example.com/xy/index.php
%如果我像这样在wp-config.php中设置站点url,postname%permalinks也可以工作
定义('WP_HOME','http://example.com/xy’ );代码>
define('WP\u SITEURL','http://example.com/xy’ );代码>
然而,我需要保持网站的url路径相对,所以这不是一个理想的修复
我尝试过禁用所有插件,并将主题更改为默认,但没有效果。
我已经为我的根目录启用了AllowOverride。
我在apache中启用了mod rewrite,我的.htaccess由WP生成,如下所示:
RewriteEngine On
RewriteBase /xy/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /xy/index.php [L]
</IfModule>
重新编写引擎打开
重写基/xy/
重写规则^index\.php$–[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/xy/index.php[L]
所以我通过在functions.php中添加以下内容来解决这个问题
function disable_front_page_redirects($redirect_url) {
if( is_front_page() ) {
$redirect_url = false;
}
return $redirect_url;
}
add_filter( 'redirect_canonical', 'disable_front_page_redirects' );
看起来你有/xy/子文件夹,在那里你已经安装了WP,当你最后添加斜杠时,你的站点工作吗?从你的代码中重新检查你的htaccess,where is opening指令?添加斜杠返回相同的结果,my.htacess似乎也正确配置了mod_rewrite.c。最后,我通过编辑functions.php解决了这个问题