views:

109

answers:

2

I have a PHP MVC framework I've built from scratch which uses the traditional domain.com/controller/action URL routing. While I'm currently handling the below conversion in the router I'd like to replace them in the URL for cosmetic reasons.

For example:

controller/action?filter=bank

Becomes:

controller/action/filter/bank

I've done a bit of experimentation with a regex but can't seem to find a match. I'm also not sure how to rewrite it using RewriteCond.

Thanks in advance.

A: 

The Zend Framework URL format is nearly identical to this, and here's what they use:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

If your server-side script is PHP, you could use this to grab the url parts:

$request_parts = explode('/', $_SERVER['REQUEST_URI']);
$controller = $request_parts[0];
$action = $request_parts[1];
// etc...
Sonny
Ross
I understand the reasons to make internal URLs clean, but it seems odd to do a redirect on a `GET` request simply to clean up the URL.
Sonny