Jump to content

Master Page With Pretty Urls?


johnywhy

Recommended Posts

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:

 

<!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 "header.php"; ?>
                </TD>
            </TR>
            <TR>
                <TD colspan="3">FOOTER</TD>
            </TR>
        </TABLE>        
    </body>    
</html>

 

yes, yes, i know tables are satan, you don't have to tell me. please keep replies to the question above.

Link to comment
Share on other sites

Tables are satan, you really should... oh wait...

 

This is done with mod_rewrite, which is an Apache module that you must have activated. You will then simple need to create a .htaccess file for you site that contains the approriate rewrite rules. And then, and this is important, you update all links in your scripts to point to the 'pretty URL' (but don't change anything about how you are working with the $_GET variables, just the output of your links). A simple example of the sort of thing you would need for this task.

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#check not a real file or directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
#rewrite the url to where the actual file is
RewriteRule ^([a-zA-Z0-9_-]+)$ master?contentpage=$1
</IfModules>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.