homepage Welcome to WebmasterWorld Guest from 54.227.171.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Dynamic page generation stumper
siteseo

10+ Year Member



 
Msg#: 3641 posted 3:33 pm on May 23, 2005 (gmt 0)

I've read the charter and combed through the stuff at apache.org, but haven't been able to figure out how to accomplish the following, or even tell if it's possible. Any help is appreciated -

I have a database-driven website consisting of a template.php page and an index.php page. The navigation for the site is pulled from the database and pages are created on-the-fly once requested.

The way this works is, the index page populates with nav items (drawn from MySQL) - when you click on a nav item the new page pulls the appropriate content and populates the template.php page. I'm using mod rewrite to convert the name of the template.php page to /nav-name/index.php

This is the line I do this with:
RewriteRule ^(.*)/index.php(.*)$ /template.php?page=$1

So with 10-pages of content in the SQL table, there's an index page in the root folder, and 9 more sub-folders with index pages of their own, which are really just mod-rewritten template.php pages.

What I'd LIKE to do is, instead of generating the pages in a folder (/nav-name/index.php) I'd like to keep them in the root folder - www.example.com/nav-name.php and still be able to populate the template page with the appropriate content.

Is this possible to do using mod rewrite, and if so - how?

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3641 posted 3:57 pm on May 23, 2005 (gmt 0)

Change the code in template.php to create 'pages' using '/nav-name.php' instead of '/nav-name/index.php'. You can hard-code this or use preg_replace if the pagenames are coming directly out of the SQL data.

Then modify your rewriterule to change requests for '/nav-name.php' to '/template.php?page=nav-name' instead of rewriting '/nav-name/index.php' to '/template.php?page=nav-name'. You will have to add an exclusion for template.php itself, so that it doesn't get rewritten itself, creating an infinite loop -- See RewriteCond %{REQUEST_URI} to get started on the exclusion part.

Once you accomplish this, you'll probably want to redirect all of your old URLs to the new scheme. That's another subject, and one you should probably ignore until you get the main problem worked out.

Jim

siteseo

10+ Year Member



 
Msg#: 3641 posted 7:24 pm on May 24, 2005 (gmt 0)

That worked - thanks for the tip. For anyone interested, here's what I ended up using:

RewriteCond %{REQUEST_URI}(space)!^template.php
RewriteRule ^(.*).php /template.php?page=$1

Leave a space where (space) is...

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3641 posted 12:30 am on May 25, 2005 (gmt 0)

Now, bolt on the turbocharger:

RewriteCond $1 !^template$
RewriteRule ^([^.]+)\.php$ /template.php?page=$1 [L]

(Just makes the patterns more specific, which speeds up processing. The pattern ".*" should be avoided anywhere but at the end of a pattern.)

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved