php - Wordpress 重写规则不适用于“name”,但适用于“p”
问题描述
如果我像这样设置 Wodpress 重写规则:
function lf_blog_add_rewrites()
{
add_rewrite_rule(
'^blog/([^/]+)$',
'index.php?name=somepost-slug',
'top'
);
}
add_action( 'init', 'lf_blog_add_rewrites' );
我得到一个 404 页面。
以下工作完美,但是......
function lf_blog_add_rewrites()
{
add_rewrite_rule(
'^blog/([^/]+)$',
'index.php?p=4567',
'top'
);
}
add_action( 'init', 'lf_blog_add_rewrites' );
我正在尝试链接以获取“/blog/slug-of-post”以链接到该页面。我可能做错了什么?
最后,如果由于某种原因这是不可能的,我可以看到: index.php?name=some-slug 似乎做了 301 重定向到正确的地方。那么如何在不破坏 WP .htaccess 重写规则的情况下设置 URL 重写呢?
解决方案
推荐阅读
- python - Django models.py 年份字段
- laravel - WhereHas on 关系
- java - 未调用自定义 Spring 注释
- swift - 如何解决 CoreML - 验证输入失败 - 形状不在允许的形状的枚举集中
- php - 使用 CodeIgniter-3.1.10 在子文件夹中路由控制器和方法
- c# - 我无法将数组作为函数参数传递。我该如何解决?
- javascript - 如何将嵌套 JSON 响应中的数据显示到 ReactJS 中的表中
- c# - 如何在软删除中获取参考数据?
- angular - 配置 K8s nginx 入口以将流量路由到两个单独的 Angular SPA 站点
- amp-html - 如何在 amp 页面的不同服务方法之间同步 CLIENT_ID?