A
A
annonimus2017-09-15 17:26:42
Nginx
annonimus, 2017-09-15 17:26:42

How to make .htaccess and nginx work?

Good day to all! Guys, the output from the winginx.com and anilcetin.com htaccess converters doesn't give the desired result. Can any of you help me set up a redirect in nginx?
Actually here is the code...

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteRule ^(comments)($|/) - [L]
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Zubkov, 2017-09-15
@annonimus

This config should help

server {
        server_name www.site.com site.com;
        listen 80;
        port_in_redirect off;

        root /var/www/site/public; <----ВНИМАНИЕ НА ЭТУ СТРОКУ, PUBLIC ОБЯЗАТЕЛЕН
        index index.php;

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

        # Cache static files for as long as possible
        location ~*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|cur)$ {
        expires max;
        log_not_found off;
        access_log off;
        }

        location ~ \.php$ {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

V
Vladimir Mukovoz, 2017-09-15
@castomi

No way, htaccess doesn't work in nginx. Everything needs to be configured in the Nginx virtual host. Converters are nonsense, when I switched to nginx I tried to fool fate, in the end I just read the documentation and wrote all the rules myself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question