简体   繁体   中英

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

I tried this code and I put it in the 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

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