Clean Fancy URL Script... HELP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

Clean Fancy URL Script... HELP

Post by orbstra »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


OK I am writing a script for a blogging application. I have designed my site so depending on the URL request, it include()s different content. Here is the beef of it (simplified):

Code: Select all

$request = $_SERVER['REQUEST_URI']; //Gets Full URL
$dirs = parse_url($request, PHP_URL_PATH); //Gets all URL Dirs
$url = explode("/", $dirs); //Puts URL Dirs into array $url
if($url[0] == 'FOO'){include('foo.php')}
if($url[0] == 'FOO' && $url[1] == 'BAR'){include('foobar.php')}
the only problem is I get a 404 error, is there anyway I can toss some sort of .htaccess in the main dir of my app so it does not look for REAL directories


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

the only problem is I get a 404 error, is there anyway I can toss some sort of .htaccess in the main dir of my app so it does not look for REAL directories
You need a rewrite such as the one the zend framework uses

Code: Select all

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
js, ico, gif, jpg, png and css can be requested as usual everything else is redirected to index.php

Incidentally what you are writing is called a front controller and they have been written by other people before (just look at any framework), probably better. So you shouldn't reinvent the wheel if you don't have to.
Post Reply