On NGINX I am trying to figure out how to keep nice URL in address bar after redirecting to the php file. I have tried all the mentioned below in the code and it works fine but no matter if use redirect or proxy, I still see www.mydomain.com/products.php in the address bar. And I need to keep the address looking as www.mydomain.com/products . Any ideas please?
server {
server_name mydomain.com www.mydomain.com;
root /var/www/mydomain.com;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
location /products {
#rewrite ^/products$ /products.php last;
#try_files $uri $uri/ /products.php;
proxy_pass http://localhost/products.php;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Resolved, I overcomplicated that, the simplest way works fine.
location /products {
rewrite ^/products /products.php last;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.