[英]Redirect to the front page if the user access the website with $_SERVER['REQUEST_URI']
I am trying to know if the user access the website from the domain it self (" http://mydomain.com ") or access it using such url (" http://mydomain.com/about ") and redirect him to the front page 我想知道用户是从自己的域名(“ http://mydomain.com ”)访问网站还是使用此类URL(“ http://mydomain.com/about ”)访问网站并将其重定向到头版
I tried this code and I put it in the page.tpl.php 我尝试了这段代码,并将其放在page.tpl.php中
if($_SERVER['REQUEST_URI'] !="/"){header( 'Location: http://www.mydomain.com' );}
but if the user click any link on the home page its keep redirect him. 但是如果用户单击主页上的任何链接,它将继续重定向他。
Please help 请帮忙
Try the below code in this i am using regular expression to find that that if the request came from your site or not 尝试下面的代码,因为我使用正则表达式来发现请求是否来自您的网站
if(preg_match('#^https?\://(?:www\.)?mydomain\.com/?$#',$_SERVER['HTTP_REFERER'])){
//matched
}else{
// redirect to other index page
}
IT will work for you IT将为您服务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.