在客户端创建重定向时,已将多个站点合并到单个站点中。
如果子页面不存在,我如何设置规则重定向到父页面,而不是直接重定向到404。
Eg重定向自
example.com/au/location1/staff (Does not exist)
至example.com/au/location1
(这些子页面中有很多已经不存在了)在客户端创建重定向时,已将多个站点合并到单个站点中。
如果子页面不存在,我如何设置规则重定向到父页面,而不是直接重定向到404。
Eg重定向自
example.com/au/location1/staff (Does not exist)
至example.com/au/location1
(这些子页面中有很多已经不存在了)如果你想在你的生活中做到这一点。htaccess文件以确保提前重定向,方法如下。
首先使用重写条件检查页面是否不存在:
RewriteCond %{REQUEST_FILENAME} !-f
接下来是不存在的页面的重写规则RewriteRule ^/au/location1/(.*)$ http://example.com/au/location1/ [L]
总而言之:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/au/location1/(.*)$ http://example.com/au/location1/ [L]
现在如果页面示例。com/au/location1/staff存在,则不会重定向,但是如果页面示例存在。com/au/location1/staff不存在,用户将被重定向到示例。com/au/location1/。请注意,这将应用于示例中的所有子页面。com/au/location1/e,即任何不存在的子页面都将重定向到父页面。
我希望我正确地解释了你的问题,这会有所帮助。
在template_redirect 如果不是文件,请重定向到父级。请小心,如果有人正在寻找网站漏洞,那么每404将呈现您的主页。
function __404_template_redirect()
{
if( is_404() )
{
$req = $_SERVER[\'REQUEST_URI\'];
if ( is_file( $req )) {
return; // don\'t reduce perf by redirecting files to home url
}
// pull the parent directory and convert to site url
$base_dir = dirname( $req );
$parent_url = site_url( $base_dir );
// redirect to parent directory
wp_redirect( $parent_url, 301 );
exit();
}
}
add_action( \'template_redirect\', \'__404_template_redirect\' );
请帮助我克服重定向问题。我需要在子域上工作,而不是在主域上工作,但这里两个域是不同的。我所做的是-将所有(website.com)文件复制到另一个子域(demo.websiteA.com),并根据wp配置更改数据库名称。php文件。但每当我尝试打开演示时。网站a。com它重定向到网站。com公司请帮帮我提前感谢