sphinx Posted September 24, 2010 Share Posted September 24, 2010 Hi I had it on my old site but forgot what I put in the index.php file. Basicly, I want something like this: http://site.com/index.php?go=home or: http://site.com/index.php?home Does anyone know what I put in the index.php file to specify link and where it redirects too? Thank you. Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/ Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 everything behind the question mark is called the query string. To get it you use $_SERVER['QUERY_STRING']; for example: echo $_SERVER['QUERY_STRING']; http://localhost/index.php?home will show 'home' http://localhost/index.php?go=home will show 'go=home' Using $_GET will give you an array of all the keys and values in the query string: echo $_GET['go']; will show 'home'. Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114935 Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 yes but it's not a search query, just a link. Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114939 Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 thanks, im getting there, i tried this: <?php $id=5; $location="index.php?id=go"; header( 'Location:http://www.google.com'); ?> if i access my website root, it redirects me too google even without the ?id=go in the link. Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114942 Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 header("location: http://google.com/?id=go"); If you want it in variables: $str = "id=go"; header("location: http://google.com/?". $str ); Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114943 Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 That still redirects on root, Basicly, when user clicks a link which is: http://mysite.com/?redirect it takes them to another part of the site, that code does: http://www.google.com/?id=go when i access root. Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114948 Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 I'm confused. Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114960 Share on other sites More sharing options...
sphinx Posted September 24, 2010 Author Share Posted September 24, 2010 this is what i mean: <?php $link = 'http://www.google.com'; if (@$_GET['id'] == 'go') header('Location: ' . $link); ?> but i want it to work like: site.com/?go = redirects to google. instead of: site.com/index.php?id=go Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114967 Share on other sites More sharing options...
Chris92 Posted September 24, 2010 Share Posted September 24, 2010 $link = 'google.com'; if( !empty($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == 'go' ) { header("location:" . $link); } Link to comment https://forums.phpfreaks.com/topic/214265-how-to-make-a-redirect-like-this/#findComment-1114981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.