Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an .htaccess file in Nginx?

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] 
like image 895
Sandeep Bhaskaran Avatar asked Mar 03 '16 08:03

Sandeep Bhaskaran


People also ask

Can we use htaccess in nginx?

Nginx does not use . htaccess files like Apache does. This means that configuration previously done in . htaccess files now has to be done in a different format, explained in the Nginx documentation.

What is htaccess nginx?

htaccess for nginx enables the nginx high performance webserver to deal with . htaccess files. . htaccess files are mainly used for access control and URL rewrite instructions and are widely known across the web community.


1 Answers

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):

  • import your .htaccess to nginx.conf (maybe the htaccess to nginx converter helps you)
  • use authd-htpasswd (I didn't try it)
like image 168
uzsolt Avatar answered Sep 20 '22 21:09

uzsolt