Page 1 of 1

Pretty Urls With Master Page?

Posted: Mon Aug 09, 2010 2:39 am
by johnywhy
hi, my site has header, footer, and sidebar which repeat on all pages. my goal is to contain the layout, header, footer, sidebar, and content all in separate files, and assemble them with php. problem-- getting pretty urls.

my current structure has only 1 url. each subpage is loaded with a parameter in the url indicating what to load into the content area of the page. for example:

About page url: http://mysite.org/master?contentpage=about
Events page url: http://mysite.org/master?contentpage=events

problem: i want these pages to have prettier urls for sharing. I mean, i want them to have simple urls which make them appear to be static html pages:
http://mysite.org/about
http://mysite.org/events

so question, is there way to achieve that with my current structure? If not, is there a different structure which will achieve simple urls, yet still keep layout in one file, and header, footer, sidebar, and content in other files?

my master page:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Include Test</title>        
    </head>    
    <body>        
        <TABLE WIDTH="100%" border=1>
            <TR>
                <TD class="headercell" colspan="3">
                    HEADER<br>
                    <? include "header.php"; ?>
                </TD>
            </TR>
            <TR>
                <TD class="leftsidebar">LEFT SIDEBAR
                    <? include "leftsidebar.php"; ?></TD>
                <TD class="bodycell">BODY CONTENT
                    <br>
                    <? $pagename=$_GET["contentpage"]; ?>
                    <? include $pagename.".php"; ?></TD>
                <TD>RIGHT SIDE-BAR<br>
                    <? include "rightsidebar.php"; ?>
                </TD>
            </TR>
            <TR>
                <TD colspan="3">FOOTER</TD>
            </TR>
        </TABLE>        
    </body>    
</html>
​
yes, yes, i know tables are the devil, you don't have to tell me. please keep replies to the question above.

Re: Pretty Urls With Master Page?

Posted: Mon Aug 09, 2010 3:50 pm
by axcrow
You could redirect everything to index.php with htaccess - mod_rewrite - without changing the url - hidden redirect.
Then in index.php you parse the $_SERVER['REQUEST_URI'].
for example you could explode the request_uri by '?' and then by '/' - or do it with regexp
finally you include the 'page' you got in your master page =) just dont forget to validate first - since it is user input.

Re: Pretty Urls With Master Page?

Posted: Mon Aug 09, 2010 8:50 pm
by josh
You should look into concepts of MVC & Routing if you want beatiful URLs and organized codebases. Here's some random tutorial http://allseeing-i.com/Bare-bones-Rails ... er-for-PHP