Page 1 of 1

Clean Fancy URL Script... HELP

Posted: Thu Dec 28, 2006 12:17 am
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]

Posted: Thu Dec 28, 2006 5:02 am
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.