mady Posted September 13, 2009 Share Posted September 13, 2009 Actually I wanted to have a index.php It will get content from a page: http://mysite.com/main.htm but I want to have links with similar style like http://mysite.com/index.php?view=help it will then fetch help.htm instead of main.htm similarly, http://mysite.com/index.php?view=aboutus and then it will fetch aboutus.htm and if the given option is not corrent then it will fetch 404.htm. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/ Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 index.php <?php echo file_get_contents($_GET['view'].'.htm'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917490 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 you can add some error checking and also move your html files to a separate folder to be organized <?php $_GET['view']=(file_exists('html/'.$_GET['view'].'.htm'))?$_GET['view']:'home'; echo file_get_contents('html/'.$_GET['view'].'.htm'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917491 Share on other sites More sharing options...
mady Posted September 13, 2009 Author Share Posted September 13, 2009 thanks, would that work for php files as well? and what if I want to define certain .html, .php or urls and rest goes to 404.htm Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917492 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 thanks, would that work for php files as well? and what if I want to define certain .html, .php or urls and rest goes to 404.htm you should stick with either htm or html not both... i guess you can pass another variable... there are probably better ways <?php $types=array('php','html','link'); $_GET['t']=(in_array($_GET['t'],$types))?$_GET['t']:'html'; $_GET['view']=(file_exists('html/'.$_GET['view'].'.htm'))?$_GET['view']:'home'; switch($_GET['t']){ case 'html': echo file_get_contents('html/'.$_GET['view'].'.htm'); break; case 'php': header('location: '.$_GET['view'].'.php'); break; case 'link': header('location: '.$_GET['view']); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917494 Share on other sites More sharing options...
mady Posted September 13, 2009 Author Share Posted September 13, 2009 thanks the html works but not the php and url. can you explain how it's supposed to work? Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917496 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 for php: index.php?view=test&t=php for link: index.php?view=http://google.com&t=link Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917498 Share on other sites More sharing options...
mady Posted September 13, 2009 Author Share Posted September 13, 2009 it worked thanks but instead of redirecting (taking away) is it possible to fetch the content? Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917500 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 <?php $types=array('php','html','link'); $_GET['t']=(in_array($_GET['t'],$types))?$_GET['t']:'html'; $_GET['view']=(file_exists('html/'.$_GET['view'].'.htm'))?$_GET['view']:'home'; switch($_GET['t']){ case 'html': echo file_get_contents('html/'.$_GET['view'].'.htm'); break; case 'php': echo file_get_contents('http://'.$_SERVER['SERVER_NAME'].'/'.$_GET['view'].'.php'); break; case 'link': echo file_get_contents($_GET['view']); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917501 Share on other sites More sharing options...
mady Posted September 13, 2009 Author Share Posted September 13, 2009 Thanks, you are cool the html files works but not the php and urls with the pattern you said earlier. Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917506 Share on other sites More sharing options...
mady Posted September 14, 2009 Author Share Posted September 14, 2009 the PHP and URL isn't working, can you please fix it? Quote Link to comment https://forums.phpfreaks.com/topic/174058-trying-to-have-a-single-url-for-different-web-pages/#findComment-917963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.