REST-style URLs and PHP

I find it very hard to catch my head using REST-style URLs. Can I help a little with this? Right now I have a query string, for example:

example.com/calendar_expanded?date=1270094400

I have a mod rewrite that hides the .php extension. Like me

  • Do it calendar_expanded/date/1270094400.
  • $_GET values ​​from url after the fact?

I like the concept, but working 16-hour days to meet a deadline of a whole month reflect my brain.

Thanks for the help.

+3
source share
3 answers

If you want to create quite a few REST URLs, you should consider using the PHP framework, which uses the Front Controller design pattern .

, , URL-, .

. Symfony RESTful .

URL- BTW RESTful , - , . , . (.. -), "" GET .

, , . GET .

+3

$_SERVER[ 'REQUEST_URI' ] $_SERVER[ 'PATH_INFO' ], $_GET.

$_SERVER[ 'REQUEST_URI' ] /calendar_expanded/date/1270094400?quertStringParams=1&etc...
$_SERVER[ 'PATH_INFO' ] /calendar_expanded/date/1270094400

, , explode() . $_SERVER[ 'PATH_INFO' ] , $_GET.

+3

Is this what you are 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 when CakePHP did when it first came out ... dunno if it still does ...

+2
source

Source: https://habr.com/ru/post/1729637/


All Articles