How can I use an .htaccess file in Nginx?

Sandeep Bhaskaran picture Sandeep Bhaskaran · Mar 3, 2016 · Viewed 92.8k times · Source

I am currently migrating my website from Apache to nginx, but my .htaccess file is not working. My website is inside the /usr/share/nginx/html/mywebsite folder. How can I use .htaccess in my nginx server?

This is my .htaccess file:

RewriteEngine on
RewriteRule video/watch/([a-zA-Z0-9_@$*-]+)/?$ "videos-single.php?id=$1" [NC]

Answer

uzsolt picture uzsolt · Mar 3, 2016

Nginx doesn't support .htaccess (see here: "You can’t do this. You shouldn’t. If you need .htaccess, you’re probably doing it wrong.").

You've two choices (as I know):