RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
Options -Indexes
I need to convert this rule to htaccess
to nginx
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
Options -Indexes
I need to convert this rule to htaccess
to nginx
In nginx use the try_files
and instead of the variable $_GET['url']
use REQUEST_URI
nginx.conf should look something like:
location / {
autoindex on;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
An example to get the PATH (based on a framework I did link ):
function UrlPath()
{
static $pathInfo;
if ($pathInfo !== null) {
return $pathInfo;
}
$sname = $_SERVER['SCRIPT_NAME'];
$reqUri = empty($_SERVER['REQUEST_URI']) ? null :
preg_replace('#\?(.*)$#', '', $_SERVER['REQUEST_URI']);
$pathInfo = rtrim(strtr(dirname($sname), '\', '/'), '/');
$pathInfo = substr(urldecode($reqUri), strlen($pathInfo) + 1);
$pathInfo = '/' . ($pathInfo === false ? '' : $pathInfo);
return $pathInfo;
}
To use just call it like this:
echo UrlPath();
Instead of:
echo $_GET['url'];
This way with the UrlPath
function will not affect the GET variables, if you need to try_files
to apache do so:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]