Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 在Apache RedirectMatch上为WordPress计算_Regex_Wordpress_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Regex 在Apache RedirectMatch上为WordPress计算

Regex 在Apache RedirectMatch上为WordPress计算,regex,wordpress,.htaccess,mod-rewrite,redirect,Regex,Wordpress,.htaccess,Mod Rewrite,Redirect,这是类似的,但我没有使用Perl模块 问题 我正在使用WordPress 4.3,我需要为permalinks结构添加一个类似于1122000的数字 这是我的默认URL结构: mysite.com/?post_type=orders&p=139 mysite.com/orders/1122139 这是理想的permalink结构: mysite.com/?post_type=orders&p=139 mysite.com/orders/1122139 请注意,我们不能将1

这是类似的,但我没有使用Perl模块

问题 我正在使用WordPress 4.3,我需要为permalinks结构添加一个类似于
1122000
的数字

这是我的默认URL结构:

mysite.com/?post_type=orders&p=139
mysite.com/orders/1122139
这是理想的permalink结构:

mysite.com/?post_type=orders&p=139
mysite.com/orders/1122139
请注意,我们不能将
1122
连接到
post\u id
中,因为
post\u id
将来可能超过
999

我的努力 在我的第一次尝试中,我使用了
add\u rewrite\u rule
函数:

function my_rewrite_basic() {
    add_rewrite_rule( '^orders/1122([0-9]+)/?', 'index.php?post_type=orders&p=$matches[1]', 'top');
}
add_action('init', 'my_rewrite_basic');
仅当id低于
1000
时,此选项才有效

在第二次尝试中,我直接使用Apache RedirectMatch,如下所示:

RedirectMatch 301 ^/orders/(\d+) /?post_type=orders&p=($1-1122000)
.htaccess
文件中,没有成功


有没有其他方法可以实现基于post_id的7位序列号?

正则表达式不允许您进行数学运算<代码>重写规则也不允许您进行数学运算

您应该考虑修改数据库中的数据。您可以将该数字添加到数据库中的post id中,同时注意不要破坏外键约束(这意味着,您可以使用更新级联上的
选项配置显式外键,或者手动更新包含对post id引用的每个字段


另一个选择是为wordpress编写路由插件,这将允许您强制执行您喜欢的任何重写规则。

简单的答案是,您不能使用正则表达式进行数学运算。您需要在后端页面上使用一些代码来捕获请求并对其进行任何数学处理