.htaccess - Obtain url paths using php code without htaccess
Get the solution ↓↓↓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.
Answer
Solution:
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']
Answer
Solution:
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.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illuminate\http\exceptions\posttoolargeexception
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.