我想在wordpress中立即重定向网址。这是我的脚本代码。
JS CODE
jQuery(document).ready(function() {
var x=window.location.href;
if(x=='http://example.com/') {
window.location.href='http://example.com/home';
}
});
当我输入url example.com/时,我希望它可以立即重定向到example.com/home而不显示example.com/页面。我想在我的网站上按Enter键时看到example.com/home页面。
答案 0 :(得分:2)
最好在htaccess文件中创建重定向,如下所示:
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
答案 1 :(得分:1)
答案 2 :(得分:1)
Wordpress提供了一个简单易用的重定向功能。只需将其放在模板的最顶部:
<?php
wp_redirect( 'http://example.com/home' );
exit;
?>
答案 3 :(得分:0)
使用Wordpress框架本身的一种方法是使用wp_redirect - https://codex.wordpress.org/Function_Reference/wp_redirect
所以,你可以加入wordpress的wp动作(以确保已设置$ post项目并运行以下内容。它将检查这是否是在阅读设置和重定向中设置的网站的主页如果是的话。
这不是解决此问题的最佳方式,因为它会加载部分页面,但它可能是您的问题的快速临时解决方案。只需将此添加到functions.php文件
即可add_action('init','redirect_home');
function redirect_home(){
if(is_front_page()||is_home()){
wp_redirect(get_site_url().'/home');exit;
}
}
答案 4 :(得分:0)
使用以下命令编辑htaccess文件:
RewriteEngine On
RewriteRule ^$ /home [R=301,L]
RewriteCond %{REQUEST_URI} ^/?