简体   繁体   中英

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

<?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? 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 {
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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