【发布时间】:2021-10-19 06:50:48
【问题描述】:
在wordpress中使用以下内容来获取特定帖子的结果
site_url?p=12
但如果它不是数字怎么办。让我们尝试使用site_url?p=test 而不是转到 404 它显示空白页?尝试使用正则表达式重定向
^site_url?p=[0-9]
但它没有成功。由于这个 p 是 wordpress 中的保留关键字。
任何想法如何检查它的值,以便如果它不是数字,我可以创建条件?
【问题讨论】:
-
您知道
?是正则表达式中的元字符,需要转义吗?\?? -
我使用的是redirect plugin,它确实允许我在没有\的情况下添加
?? -
你确定吗?
If you want to match a character that is part of the regular expression syntax then you must escape it. For example, if you want to match ? then you will need to put \? as ? on its own has a special meaning.
标签: php regex wordpress redirect wordpress-theming