php - wordpress自定义重写规则

标签 php wordpress .htaccess mod-rewrite

我正在尝试让自定义重写规则起作用,但目前它不起作用。也许有人可以提供帮助?

我想要的说出 url 看起来像这样:domain/the-brand/xyz

domain/?pagename=brand-2&brand=xyz 是工作 url...

我已经在 functions.php 中添加了一个自定义标签:

function custom_rewrite_tag() {
  add_rewrite_tag('%brand%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

和一个自定义规则,但似乎有一个错误:

function custom_rewrite_rule() {
    add_rewrite_rule('/the-brand/([^/]*)' , 'index.php?pagename=brand-2&brand=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);

最佳答案

看起来您做对了,您只想刷新永久链接 as noted here

Note that these rules are usually called inside the init hook. Furthermore, permalinks will need to be refreshed (you can do this from your admin under Settings > Permalinks) before the rewrite changes will take effect. Requires one-time use of flush_rules() to take effect. See also Flushing Rewrite on Activation.

关于php - wordpress自定义重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936873/

相关文章:

php - 使用任意数量的参数通过 htaccess 漂亮的 URL

.htaccess - 301 从主域(www 和非 www)重定向到子域

php - 使用 Moodle 上的外部数据库身份验证插件防止本地重复

xml - 为 wordpress 帖子创建 rss.xml 文件

css - 为什么我的 wordpress 主题没有背景图片?

mysql - 在 SQL 中将 longtext 排序为 int

php - 如何根据下拉选择更改div中的内容

php - 将 CSV 字符串转换为数组键和值 1 或 true

php - 从用户输入构建动态 PHP 准备语句

apache htaccess 使用别名重写