The short answer here is: you can't. NGINX does not provide native htaccess support. However, that doesn't mean it isn't possible at all.

It is possible to convert htaccess rules to NGINX rules so you can still get the same behavior. There are numerous tools out there that can easily convert something like this:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

Into valid NGINX rules, a few of those tools summed up:

NGINX even wrote a blog article about converting the htaccess rules to NGINX rules.

Considering the above htaccess example, most tools will convert them into something like this:

server {
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
}


18 August 2021 (last updated 2 years ago)

12088 views

Written by Dennis Smink

Dennis brings over 6 years of hands-on experience in server management, specializing in optimizing web services for scalability and security.

Back to Server


Start free trial