jonoc33 Posted October 9, 2008 Share Posted October 9, 2008 Hey guys, Title pretty much says it. How would I make a link of a server-side page a folder layout instead of the normal $_GET tags? What is it's specific name? I can't really find much on google on it. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/ Share on other sites More sharing options...
Andy-H Posted October 9, 2008 Share Posted October 9, 2008 $p = htmlentities($_GET['p'], ENT_QUOTES); $id = htmlentities($_GET['id'], ENT_QUOTES); require_once "../" . $p . "/" . $id; I think ??? Would need protection from external files too. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660711 Share on other sites More sharing options...
jonoc33 Posted October 9, 2008 Author Share Posted October 9, 2008 I didn't really mean it like that. That's really basic stuff. Say I have this link: http://www.site.com/index.php?page=home I want to make it this: http://www.site.com/home/ But it's like a virtual folder, the folder isn't actually on the server. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660713 Share on other sites More sharing options...
Andy-H Posted October 9, 2008 Share Posted October 9, 2008 Ahh, not a clue on that one. Sry. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660714 Share on other sites More sharing options...
jonoc33 Posted October 9, 2008 Author Share Posted October 9, 2008 Anyone else know how to set this up? I searched PHP virtual directory on google and that relates to what my question is. It has something to do with modifying your .htaccess file. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660715 Share on other sites More sharing options...
beansandsausages Posted October 9, 2008 Share Posted October 9, 2008 mod rewright maybe? http://corz.org/serv/tricks/htaccess2.php Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660718 Share on other sites More sharing options...
unkwntech Posted October 9, 2008 Share Posted October 9, 2008 The most common way of doing it is with mod-rewite which can give you: doamin.tld/page/myvar I wrote something up for a client that did not have access to mod-rewrite: $pages = array('home', 'products', 'services'); //This is actually an SQL query but for the sake of example. $parts = $_SERVER['REQUEST_URI']; $parts = preg_replace('%\/index\.php%', '', $parts); $parts = preg_split('%/%', $parts); foreach($parts as $part) { if(!(is_null($part) || strlen($part) < 1)) { $uriParts[] = $part; } } if(in_array(strtolower($uriParts[0], $pages))) { $sql = "SELECT title, text FROM content WHERE name='" . mysql_real_escape_string($uriParts['0']) . "' AND published='1'"; //query.... } With this the links look like domain.tld/?/home or domain.tld/index.php?/home/ Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660723 Share on other sites More sharing options...
jonoc33 Posted October 9, 2008 Author Share Posted October 9, 2008 It's working, but images don't work for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660728 Share on other sites More sharing options...
unkwntech Posted October 9, 2008 Share Posted October 9, 2008 You have to use exact paths to images because the browser is stupid it thinks that it should look for images under doamin.tld/home/image.ext Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660730 Share on other sites More sharing options...
poleposters Posted October 9, 2008 Share Posted October 9, 2008 I've been curious about doing something similar for my site. Are there any SEO or other advantages? Or is just to make URLs neat and tidy? Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660736 Share on other sites More sharing options...
jonoc33 Posted October 9, 2008 Author Share Posted October 9, 2008 No advantages, just makes it cleaner. Although several problems emerge. Making the images direct links still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660737 Share on other sites More sharing options...
unkwntech Posted October 9, 2008 Share Posted October 9, 2008 Which solution are you using mod-rewrite or what I posted? Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660738 Share on other sites More sharing options...
jonoc33 Posted October 9, 2008 Author Share Posted October 9, 2008 mod-rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660740 Share on other sites More sharing options...
unkwntech Posted October 9, 2008 Share Posted October 9, 2008 You will need to add an exception for the images folder, because now it is trying to make /images/ forward to your index Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660742 Share on other sites More sharing options...
jonoc33 Posted October 9, 2008 Author Share Posted October 9, 2008 How exactly do I do that? Also, for some reason my site is running incredibly slow now that i've added this to the .htaccess. Any reason why? Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660744 Share on other sites More sharing options...
jonoc33 Posted October 9, 2008 Author Share Posted October 9, 2008 Bump? Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660749 Share on other sites More sharing options...
beansandsausages Posted October 9, 2008 Share Posted October 9, 2008 Try using a true image path, <img src="Http://www.mysite.com/images/myimage.png" /> sum it like that ? ??? Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-660754 Share on other sites More sharing options...
corbin Posted October 10, 2008 Share Posted October 10, 2008 Can we see your rewrite stuff? lol ;p Quote Link to comment https://forums.phpfreaks.com/topic/127667-folder-link-article123-instead-of-normal-link-particleid123/#findComment-661522 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.