Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[Apache2] Clean urls [PHP]

Name: Anonymous 2010-02-23 18:05

I am sorry if this is the wrong board. I would like to create a site with clean urls using mod_rewrite, .htaccess and php. I have searched google and tested but I just can't figure it out 100%.

I'm aiming for a system where all the arguments given in an url would be automatically transferred to GET variables with the first two being pre-named and the others would be identifiable from the previous (always in pairs of 2).

Example of URL to convert:
  http://localhost/controllerX/viewY/id/4/page/2/
Conversion result:
  $controller == controllerX
  $view == viewY
  $id == 4
  $page == 2

I have the controller and view variable part kind of sorted (I think), but I can't get the rest of the url sorted. My current .htaccess rules:
  RewriteRule ^([^/\.]+)/?$ /index.php?controller=$1 [L]
  RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?controller=$1&view=$2 [L]

In PHP I access them like: $_GET['controller'] and $_GET['view'].

Name: Anonymous 2010-02-24 0:03

you probably don't want to hardcode a controller and view to the url/htaccess like that. i mean, yeah, that's how things are done by default in most mvc frameworks, but you usually can do more interesting routes through the router. i'd recommend looking at how cakephp's or codeigniter's router works. cakephp is kind of a piece of shit, but there's some decent parts of it, and you just endup needing an htaccess file with one rule.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List