Forum Moderators: coopster

Message Too Old, No Replies

Setting up a default home page & Permalinks

Setting up a default home page & Permalinks

         

m4tt

1:35 am on Apr 12, 2006 (gmt 0)

10+ Year Member



I have a slight problem that I can't come up with an answer for. I have set up a cms that works great however it works based on the following

www.yoursite.com/?p=home
www.yoursite.com/?p=services

So that the navigation calls up the relevant page. However when I type:

www.yoursite.com - It comes up with no data because none has been called...

Does anyone know how to set it up so if you go to

www.yoursite.com it goes to say the default home page?

Thanks in advance!

Also can anyone help with changing /?p=home ot a permalink:
/home/
/services/

etc?

Here is the code in the index.php:

<?
include("/includes/config.php");
include("/library/config.php");
include("/library/opendb.php");

$pagename=$_POST['p'];
$query=" SELECT * FROM pages WHERE pagename = '{$_GET['p']}'";
$result=mysql_query($query);
$num=mysql_num_rows($result);

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$pagename=mysql_result($result,$i,"pagename");
$content=mysql_result($result,$i,"content");
?>

<?php

if (get_magic_quotes_gpc())
{
$content = stripslashes($content);
}
?>
<? echo "$content"?>

<?
++$i;
}
?>

eelixduppy

1:41 am on Apr 12, 2006 (gmt 0)



Hello!

For the pages that you want to redirect you can use the following...

www/html/index.php
<?php
//redirect this page to your actual homepage
header("Location: [yoursite.com...]

?>

this method can be used for your other pages as well...

hope this answered your questions

m4tt

1:46 am on Apr 12, 2006 (gmt 0)

10+ Year Member



Thanks

However firefox gives me this message and all cookies are enabled?

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete

* This problem can sometimes be caused by disabling or refusing to accept
cookies.

eelixduppy

1:51 am on Apr 12, 2006 (gmt 0)



Trying using an apostrophe (') around the text in the header() function

m4tt

2:07 am on Apr 12, 2006 (gmt 0)

10+ Year Member



Still no go it reproduces the '' at each end?

eelixduppy

2:22 am on Apr 12, 2006 (gmt 0)



try adding this after the previous header() function

header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');

if this doesn't work then i don't know...sorry

i hope you get it

m4tt

2:35 am on Apr 12, 2006 (gmt 0)

10+ Year Member



Thanks heaps, still no good I have played around with a few "if" functions - Do you think this could work? I couldn't get them to work?

m4tt

3:55 am on Apr 12, 2006 (gmt 0)

10+ Year Member



Can anyone help? Is there another way to extract or set the default to extract everything?

m4tt

6:29 am on Apr 12, 2006 (gmt 0)

10+ Year Member



Does anyone know how to make this into a permalink?

www.yoursite.com/?p=Home

www.yoursite.com/home/

I have tried a few different threads but I am uncertain where to put what etc?..

Can anyone assist?

barns101

8:04 am on Apr 12, 2006 (gmt 0)

10+ Year Member



I assume that it is done using URL rewriting such as Apache mod_rewrite [httpd.apache.org]. See the Apache Web Server [webmasterworld.com] forum for more details.

alce

5:41 pm on Apr 12, 2006 (gmt 0)

10+ Year Member



Instead of redirecting the user,you could use something like this:

<?php
if(isset($_GET['p'])) {
$p=$_GET['p'];
} else {
$p='home';
}
?>

Have not tried it myself but something along those lines might help.

m4tt

11:15 am on Apr 13, 2006 (gmt 0)

10+ Year Member



Thanks gave it a shot but didn't seem to work, this one has really stumped me...

jatar_k

4:05 pm on Apr 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well I am guessing we are dealing with these 2 lines

$pagename=$_POST['p'];
$query=" SELECT * FROM pages WHERE pagename = '{$_GET['p']}'";

I don't know why you have $_POST assigned first and then unused. I am guessing that means it is unneeded. I also don't understand why $pagename is set a again later.

$pagename=mysql_result($result,$i,"pagename");

I also don't really understand the need for num rows and the loop. My thought is that it should only ever return a single row. You should be able to default it like alce showed

I would do something like this

<?
include("/includes/config.php");
include("/library/config.php");
include("/library/opendb.php");

$pagename = '';
if (!isset($_GET['p']) ¦¦ empty($_GET['p'])) $pagename = 'home';
else $pagename = $_GET['p'];

$query="SELECT * FROM pages WHERE pagename='" . $pagename . '";
$result=mysql_query($query);

if ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$content = $row['content'];
if (get_magic_quotes_gpc()) $content = stripslashes($content);
echo "$content";
}
?>

that removes the loop but there shouls only be a single row per page. The rest should work.

remember that ¦ is not a real pipe char and must be replaced with a real pipe char before testing this code

m4tt

1:58 am on Apr 14, 2006 (gmt 0)

10+ Year Member



Thanks

I get this error:

Parse error: syntax error, unexpected T_ELSE in /home/mysite/public_html/index.php on line 13

from

else $pagename = $_GET['p'];

alce

5:02 pm on Apr 15, 2006 (gmt 0)

10+ Year Member




Change

$pagename = '';
if (!isset($_GET['p']) ¦¦ empty($_GET['p'])) $pagename = 'home';
else $pagename = $_GET['p'];

to

$pagename = '';
if (!isset($_GET['p']) or empty($_GET['p'])) $pagename = 'home';
else $pagename = $_GET['p'];