I am working on a shared hosting server setting up something that was working fine on my local host and I am curious what is causing this behavior. I am redirecting URLs with Apache and mod_rewrite to a front controller with:
RewriteEngine On
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
#Redirect to front controller
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
On index.php I have a simple check setup for debugging purposes:
if(isset($_SERVER['PATH_INFO']))
{
echo $_SERVER['PATH_INFO'];
}
else
{
echo "No Path";
}
die;
Visiting http://example.com/testing outputs “No Path”
Visiting http://example.com/index.php/testing outputs /testing
This redirection was working as intended on my local host with http://example.com/testing outputting “/testing”
Does anyone know what could be causing this? Is there a more generic way of doing this redirection lesss prone to issue from host to host?
EDIT:
Outputting $_SERVER['PATH_INFO'], $_SERVER['ORIG_PATH_INFO'], $_SERVER['PHP_SELF'], $_SERVER['REQUEST_URI'] respectively shows:
path:
orig: /testing
self: /index.php
uri: /testing
What processing is being done to cause this? Is ORIG_PATH_INFO more reliable? Also it appears REQUEST_URI is accurate as well, is that a more suitable variable?
The URL is the important part. If you acces it via http://example.com/testing there is nothing between filename and query string.
-> http://www.php.net/manual/en/reserved.variables.server.php