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'].
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'].