$_SERVER['REQUEST_URI'] returns URI with context path.
For example, if the base URL of a website is http://localhost:8080/sitename/ (i.e. the context path is sitename), and I use $_SERVER['REQUEST_URI'] for http://localhost:8080/sitename/portfolio/design, it will return /sitename/portfolio/design.
I am then exploding the result to interpret my clean URLs:
$page=$_SERVER['REQUEST_URI'];
$segments=explode('/',trim($page,'/'));
$sitePage = $segments[1];//portfolio
This is working fine for my local testing environment, but on the production server, $segments[1] must become $segments[0]
In order to use the same code in development and production, is there any way to get only this part /portfolio/design, i.e. the URI without context path?
You can use virtual hosts so your test site will be on:
That way absolute paths (relative to the web-root) will be the same on the test server and the production server.
The how-to depends on the test server you are using.