How to remove the version prefix from the request URI and use the correct document root?

We need to support several major and minor versions of the web service, so we decided to use the version in the URL as follows:

http: // service / # last deployed version of service
http: // service / 1 / # symlink that points to the last deployed major version 1.x
http: //service/1.2/ # symlink that points to the last deployed minor version 1.2.x

We save all tags in folders and make symbolic links in the correct versions:

Here the root directory for apache:
lrwxr-xr-x 1 xxxx xxxx 28 May 23 15:21 1 -> / home / site / tags / 20120523084844-HEAD
lrwxr-xr-x 1 xxxx xxxx 28 Apr 27 15:21 1.1 -> / home / site / tags / 20120427152123-HEAD
lrwxr-xr-x 1 xxxx xxxx 28 May 23 08:48 1.2 -> / home / site / tags / 20120523084844-HEAD
lrwxr-xr-x 1 xxxx xxxx 28 May 24 16:12 2 -> / home / site / tags / 20120524161232-HEAD
(source code here for last deployed version)
.....

Here's the problem, because we will have the version prefix in REQUEST_URI in PHP, and the Symfony router will not match it with patterns. How can we shorten this version prefix, but still use a specific directory as the root of the document?

For example, when we make a request to http://service/1.2/some/handler/pattern, then the code from the 1.2 directory will be used, and REQUEST_URI in PHP will be / some / handler / pattern

+3
source share
2 answers

Try the following:

RewriteEngine On
RewriteBase /

RewriteCond $1 !^[0-9.]+/
RewriteRule ^(.*) /1.2/$1 [L]

, , htaccess, .

?

+1

.

, htaccess, , . REQUEST_URI , , ( REQUEST_URI E = REQUEST_URI = "something", REDIRECT_REQUEST_URI).

Symfony, , script, . , -

RewriteRule ^[1-9.]/(.*)$ - [R,QSA,NC,E=HANDLER:$1]

PHP request_uri:

$_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_HANDLER'];

PHP, , : , . - /. Request_uri , .

, Gerben .

+1

All Articles