Miley CYrus Posted August 7, 2008 Share Posted August 7, 2008 Does anyone know how to do this? (mysite.com is used as a example, it is the index.php?= is what I wanna know how to do..) www.mysite.com/index.php?=1 instead of www.mysite.com/tutorials.php www.mysite.com/index.php?=2 instead of www.mysite.com/sounds.php ect. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 That's not clean urls. Clean URLs are usually the opposite. They're replacements for the various GET parameters on a script. >_> Quote Link to comment Share on other sites More sharing options...
Miley CYrus Posted August 7, 2008 Author Share Posted August 7, 2008 Can you pelase explain how to do it then. Quote Link to comment Share on other sites More sharing options...
reconDev Posted August 7, 2008 Share Posted August 7, 2008 <?php// change "id" to what ever you want index.php?id=contact > contact.php $nav = $_GET['id']; switch ($nav) { Case "contact"; //this will be the name after ?id= include ('contact.php'); // page it corresponds to break; default: include ('default.php'); break; } ?> does that help ? Make it index.php and place all your contact in default.php Quote Link to comment Share on other sites More sharing options...
Miley CYrus Posted August 7, 2008 Author Share Posted August 7, 2008 <tr> <td class="box" style="border-bottom: 1px solid rgb(52, 73, 102);" width="167"> <a href="contact.php">Contact</a></td> </tr> That is what I have so far, how can i change it where like contact is index.php?=1 Quote Link to comment Share on other sites More sharing options...
papaface Posted August 7, 2008 Share Posted August 7, 2008 <tr> <td class="box" style="border-bottom: 1px solid rgb(52, 73, 102);" width="167"> <a href="contact.php">Contact</a></td> </tr> That is what I have so far, how can i change it where like contact is index.php?=1 The way you are trying to do it is bad for search engines, also it not very user friendly. In order for me to quickly go to your page I have to know the internal number reference. Whereas, tutorials are at tutorials.php. Catch my drift? Quote Link to comment Share on other sites More sharing options...
Miley CYrus Posted August 7, 2008 Author Share Posted August 7, 2008 not really. www.PhonePwners.com is my website (im working on it) and want it where I can click any of the nav links and have them like index?=1 - 5 instead of contact.php, call.php, sound.php, ect. i dont really care about search eng. and stuff.. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 7, 2008 Share Posted August 7, 2008 If you're url is this: www.mysite.com/index.php?page=1 Then in index.php use $_GET['page'] to retrieve the page number from the url. Now to serve whatever page you'll need to assign each page a number, eg 1 = tutorials.php, 2 = sounds.php etc, like so $pages = array(1 => 'search.php', 2 => 'sounds.php', 3 => 'otherpage.php' etc); Now to serve the requested page you'd do: if(isset($_GET['page']) && is_numeric($_GET['page'])) { $pid = $_GET['page'] if(isset($pages[$pid])) { include $pages[$pid]; } else { die('404 Note Found'); } } Quote Link to comment Share on other sites More sharing options...
papaface Posted August 7, 2008 Share Posted August 7, 2008 not really. www.PhonePwners.com is my website (im working on it) and want it where I can click any of the nav links and have them like index?=1 - 5 instead of contact.php, call.php, sound.php, ect. i dont really care about search eng. and stuff.. I am well aware of what you want. But its your grave. Quote Link to comment Share on other sites More sharing options...
mbeals Posted August 7, 2008 Share Posted August 7, 2008 I do this with one of my pages (with success). Just some things to consider: 1. if you use self recursive pages (pages that call themselves to process form data) use sessions to store the page index. On your index.php page, include something like this: <?php session_start(); function pageTranslate($id){ switch($id){ default: return 'default.php'; case 'users': return 'users.php'; case 'stats': return 'stats.php'; } } $site = isset($_GET['site']) ? pageTranslate($_GET['site']) : (isset($_SESSION['site']) ? $_SESSION['site'] : 'default.php'); $_SESSION['site'] = $site; include('$site'); ?> This first checks the get variable 'site' to see if a different page is being requested. If so, it translates the page reference into the proper php file name and stores it in the session variable. If a different page isn't being requested, it just uses whatever is stored in the session variable. If there is nothing, it show's the default page. now you only need to specify 'site' in the url when switching to a new page. You can call index.php all you want and it will continue to call the same page. It REALLY makes life easier. 2. Transform that pageTranslate function into one that queries a mysql database. You can add and reassign pages by moving stuff around in a database instead of editing the source. Use the same database table to generate your links. This makes it easier to implement user access levels too, as you can limit what links are shown to certain users and validate the link against their access rights before loading the page. 3. Learn to love modrewrite for apache and use it for common pages. Say you access the forums.php page with $site = forums and tutorials.php with $site = tutorials.php. Write modrewrite rules to that www.PhonePwners.com/forums is translated to www.PhonePwners.com?site=forums and www.PhonePwners.com/tutorials is translated to www.PhonePwners.com?site=tutorials. You don't have to do it to all of your sites, but it is handy for direct access to certain parts. Quote Link to comment 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.