View Full Version : Custom URL's
tacmig99
03-31-2007, 08:37 PM
I'm looking for a way to get all my pages to use index.php in the URL.
Something like:
http://www.example.com/index.php
Should become:
http://www.example.com/index.php?page=home
I found this code
<?php
if ($_GET['page'] == 'home') {
?>
(CONTENT)
<?php
}
?>
But the link seems to take me to index.php even if I make up a random name like index.php?page=fjsadblfj or index.php?sdjfgbkjsdbl
Any help is appreciated.
thetestingsite
03-31-2007, 08:54 PM
You would want to place the code you posted above in the index.php page. After which, you would want to edit it for your pages (using if-elseif conditionals).
Example (index.php):
<?php
$default_page = "default.php"; //the default page if the page variable is not set
//start the if-then conditionals
if ($_GET['page'] == "home") {
include('home.php');
}
elseif ($_GET['page'] == "testing") {
include('testing.php');
}
else {
include($default_page);
}
?>
Hope this helps.
tacmig99
03-31-2007, 08:59 PM
Thanks, just so I'm clear though, my index.php has nothing except the code you provided right?
Edit: hmm, can't seem to get this to work
Parse error: parse error, unexpected $end in http://www.example.com/index.php on line 16
Edit2: I found a code that I got to work.
<?php
if(!isset($_GET['page'])){
$page = "home";
} else {
$page = $_GET['page'];
}
$path = $page.".php";
if (file_exists($path)){
include($path);
} else {
echo "Sorry, the page doesn't exist...";
}
?>
Thanks for replying anyways, I appreciate the help :cool:
mburt
03-31-2007, 09:40 PM
I use a similar system on my site, in fact...
I'm looking for a way to get all my pages to use index.php in the URL.
Something like:
http://www.example.com/index.php
Should become:
http://www.example.com/index.php?page=homeBe aware that this is poor style... once you've done this, use mod_rewrite or something to change the URLs so that /index.php?page=home becomes /home or perhaps /pages/home. Also, avoid the temptation to bung everything into one huge file. Make use of includes.
I really need to get .htaccess working on my site so I can do this. I think it's a config problem.
mburt
03-31-2007, 10:33 PM
I recently found out that you can't edit the htaccess file with my hosting service :(. But ah, well. I'll live.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.