简体   繁体   English

WordPress 404.php 301重定向但排除一个目录

[英]Wordpress 404.php 301 redirect but exclude one directory

I use the following code in 404.php file, to redirect all 404 errors to home page 我在404.php文件中使用以下代码,将所有404错误重定向到首页

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?> 

Now, I want to exclude from this redirection a directory called guest How can I do that? 现在,我想从此重定向中排除名为guest的目录。我该怎么做? Thank you! 谢谢!

The solution: 解决方案:

$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if (strpos($url,'guest') == false) {
       header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
    exit();
} else {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM