0

Is there a way to obtain a url path (for example index.php/sales, extracting only 'sales') using php code without htaccess? I have an mvc project (using apache) and works fine but had to move to a vagrant server that uses nginx. From reading, I must either convert the htaccess rules to nginx server rules. But the box is pre-configured with nginx. Not sure if there is a work around here. Suggestions and workarounds are welcome. Thank you.

My htaccess file is:

RewriteBase /
RewriteCond %{REQUEST_FILENAME}%  !-d
RewriteCond %{REQUEST_FILENAME}%  !-f

# Do not route static files in the public directory
RewriteRule \.(js|css|svg|gif|jpg|jpeg|png)$ -                 [L]

RewriteRule ^/?editcategory/(.*?)/?$       /editcategory?categoryid=$1  [L]
  
# Route everything else to index.php in the public directory
# Note: name-router get variable used for public user profiles
RewriteRule ^(.*)$                index.php?name-router=$1 [QSA,L]

P.S: I am very new to nginx so don't want to complicate things the more.

tereško
  • 58,060
  • 25
  • 98
  • 150
K.Chams
  • 33
  • 5

2 Answers2

0

If you look into this, it might just hold the answer you're looking for: Get the full URL in PHP

But you're most likely looking for this one: $_SERVER['REQUEST_URI']

Werzaire
  • 78
  • 3
0

AFAIK I don't think you can achieve what you want without rewriting.

If you have changed from apache to nginx, I think this is what you are looking for:

server {

  root /var/www/mysite.com;

  index index.php;
  server_name mysite.com;

  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  }

  location / {
    try_files $uri $uri/ @fallback;
  }

  location @fallback {
    rewrite ^/(.*)$ /index.php?section=$1 last;
  }

}

Source: https://serverfault.com/a/851010

Without rewriting an url you will not be able to access the data in the url after index.php/ when the url is e.g. index.php/sales. To parse data attributes directly in the url you have to define the data in the proper way for executing a GET request. Using this format "?key1=val1&key2=val2&key3..." etc. therefore you are dependant on the rewrite.

Andrew Larsen
  • 1,257
  • 10
  • 21