Super Advanced Url Rewriting

I want to url rewrite except using PHP…

?module=audio&id=1
to
/audio/music/subcategory/artist/album/
or
http://localhost/audio/music/Дуэт/Геннадий+Морозенко/Неизвестно

I am stuck on how i should do it… the url rewriting process should be dynamic…

This looks to be a nice, light-weight routing solution.

http://route.thephpleague.com/

$url = $_SERVER['REQUEST_URI'];
$trim_leading_slashes = ltrim($url, '/');
$trim_ending_slashes = rtrim($trim_leading_slashes, '/');
$clean_url = urlencode($trim_ending_slashes);
$url_array = explode('%2F', $clean_url);

hmm i dont want to use a framework i just want a custom solution towards it because then ill have to implement into the whole CMS i’m developing…

Well, Route is built off of the FastRoute library. Maybe it’s lower level is more to your liking?

Usually rewriting is used to get one URL to go to a different place than it normally would. For instance, like if you want all URLs starting with http://www.somesite.com to go to index.php, no matter what follows the URL. index.php is then the entry point to a front controller pattern built in your system. In your front controller, you need to get the requested URI to the right resource and for that you need a router.

Scott

Its not a framework. It’s a small, stand-alone library for exactly what you want to do and more. You’re building a CMS and you don’t even know the difference between a Framework and library… c’mon man.

Not so long ago I posted sample of very simple function that handles routes with pre-defined scheme:

I think he might have been looking at the examples in the docs of Route. It uses Symfony’s http foundation component in the code examples. But then again, that would be a nice component to start off with in a CMS too.

Scott

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.