WordPress 404链接
hii我想将用户重定向,如果页面没有找到home_url(404)。这可能吗?我的目标是在URL中发现的一些特殊词,例如产品,然后将用户发送到该页面,如果不包含我的URL,则可以将用户重定向到404页。这是代码示例
$redirect = false;
if( is_404()){
$url = home_url( $wp->request );
$path_to_check_for = '/product/';
if( strpos($url, $path_to_check_for) !== false ) {
$redirect = true;
}
if($redirect == false){
header("Location: ".home_url(404));
exit;
}
}
Hii I want to redirect users if page not found to home_url(404) like this. Is this possible? My goal is some special word like product if found in url then send user to that page and if not contain my url with product then redirect to 404 page. Here is code example
$redirect = false;
if( is_404()){
$url = home_url( $wp->request );
$path_to_check_for = '/product/';
if( strpos($url, $path_to_check_for) !== false ) {
$redirect = true;
}
if($redirect == false){
header("Location: ".home_url(404));
exit;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:如果410页包含字符串'/product/'它将重定向到主页
Edited: If the 410 page contains the string '/product/' it redirects to homepage