I am trying to configure Nginx so that all requests to http://domain.com/path
are rewritten to http://domain.com/
.
I do not want a redirect, because I want the URL to still show the original path.
Example Rewrites:
http://domain.com/path/index.php -> http://domain.com/index.php
http://domain.com/path/category/books -> http://domain.com/category/books
http://domain.com/path/books.php?q=harry -> http://domain.com/books.php?q=harry
I tried alias
and root
but I could not get them to work.
location /path
{
root /var/www/html/;
}
location /path
{
alias /var/www/html/;
}
root
and alias
are meant to serve files from a specific directory not rewriting URL. You should use rewrite
.
server {
rewrite ^/path(/.*)$ $1 last;
# Your location blocks go here.
}
Read official docs for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With