Punit Makwana
Punit Makwana

Reputation: 535

What is the nginx equivalent of .htaccess

I have shifted my web hosting which support nginx only. But i have no daam idea about it. Just wanted to know what is the .htaccess equivalent for nginx. What should be its file name, where should it be saved. Also if you can help me on redirecting all request on my website to https://www it will be an cherry on cake.

Edit: I have got the answer some where else but dont know what should be the name it should be saved with and where

Upvotes: 28

Views: 39387

Answers (1)

Peyman.H
Peyman.H

Reputation: 1952

Since Nginx does not have an equivalent to the .htaccess file (i.e. no directory level configuration files), you need to update the main configuration and reload nginx for any changes to take effect.

The above Apache config essentially reads "if the path provided isn't an existing file or a directory, redirect to index.php, appending the path".

In Nginx, you will use the try_files directive to accomplish the same thing:

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

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

By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf , /etc/nginx or /usr/local/etc/nginx

Upvotes: 20

Related Questions