Search Engine Friendly URLs With PHP

Posed under PHP on November 14, 2008.

Article

Comments

Post

Travis

Nov 15 2008

Sweet! Keep up the awesome posts man!

Hugo

Nov 16 2008

I'm getting the following error: Warning: preg_replace() [function.preg-replace]: Unknown modifier ')' in /xxx/xxxxx/xxxx/xxxxxxxxxxx/xxxxxxxxxxx/xxxxx/url-test.php on line 10
Array ( [0] => )

Obviously I've x'd out the real info. But can you help with this error? Thank you!

Evan Byrne

Nov 16 2008

@Hugo: Thanks for bringing that to my attention. turns out my blog script removed a necessary backspace character in the code. It should work now.

Also, you can see a live demo of this in action at the following URL.
http://www.evanbot.com/bin/index.php/whatever/another/anything

Jordan

Mar 14 2009

Very neat! The MVC design pattern comes to mind when looking at how you accomplished this. At least the front-loader design portion of it since you have no views or models.

Evan Byrne

Mar 15 2009

@Jordan: Actually, I have implemented this into my own PHP framework. I'll be releasing it some time soon so keep an eye out!

Ack

Jun 23 2009

You're code disappeared! Kinda dissapointing since so many others found it useful.

Ravneel Chand

Jul 10 2009

The code is still on the article page:
http://www.evanbot.com/article/fancy-urls-without-mod_rewrite/3

Matt

Jul 11 2009

Is there a way to do this while hiding the "index.php" ?
I have a folder called "blog" in my directory so that www.domain.com/blog accesses the index.php in the blog folder by default. However if I use the url www.domain.com/blog/18-jan it displays "page not found". www.domain.com/blog/index.php/18-jan works great though.

Evan Byrne

Jul 12 2009

Matt, that would require some mod_rewrite. Like so:

RewriteEngine on

RewriteCond $1 !^(index\.php|img|bin)
RewriteRule ^(.*)$ index.php?page=$1 [L]

Post Comment

Capcha