I'm having a really hard time getting my head around using REST-style URLS. Can I get a little help with this? Right now I have a query string like so:
example.com/calendar_expanded?date=1270094400
I have a mod rewrite that's hiding the .php extension. How do I
- Make this
calendar_expanded/date/1270094400
happen.
$_GET
the values from the url after the fact?
I love the concept behind it but working 16-hour days to meet a deadline for an entire month is taking a toll on my brain.
Thanks for the help.
If you want to create quite a lot REST URLs you should consider to use a PHP framework that makes use of the Front Controller design pattern.
This way, every request is processed by the framework and you are flexible to design your URLs however they should look like.
E.g. Symfony supports a RESTful design out of the box.
BTW RESTful URLs only make sense if the parameters are somehow fixed and specify a resource, for example the title of a blog post. If you want to pass a parameter only to e.g. control the sorting of a table (i.e. the view of something) then this should go as a "normal" GET parameter into the query string.
In your case it looks like you want to control what day should be shown in a calendar. I personally would just use the normal GET query string here.
You need to inspect $_SERVER[ 'REQUEST_URI' ]
or $_SERVER[ 'PATH_INFO' ]
, not $_GET
.
$_SERVER[ 'REQUEST_URI' ]
will hold this /calendar_expanded/date/1270094400?quertStringParams=1&etc...
$_SERVER[ 'PATH_INFO' ]
will hold this /calendar_expanded/date/1270094400
In other words, you will have to break down these values into their seperate segments, by using explode()
and the likes. I suggest you use $_SERVER[ 'PATH_INFO' ]
as a subject, since the real query string variables will be available in $_GET
already.
Is this what you're looking for?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ calendar_expanded.php?url=$1 [QSA,L]
</IfModule>
This is what I remember CakePHP doing when it first came out... dunno if it still does...