S
S
Svoboo2018-06-11 17:57:10
Nginx
Svoboo, 2018-06-11 17:57:10

How to rewrite htaccess rules under nginx?

Here are the htaccess rules:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^rss\.xml$ /data/ rss.php [L]
RewriteRule ^sitemap\.xml$ /data/sitemap.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ data/engine. php?a=$1 [QSA,NC,L]

Tell me how to rewrite them correctly under nginx? Online htaccess->nginx converters did not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-06-12
@dodo512

server {
    listen 80;
    server_name www.site.ru;
    return 301 http://site.ru$request_uri;
}

server {
    listen 80;
    server_name site.ru;
    
    root   /var/www/html;
    
    rewrite ^/rss\.xml$ /data/rss.php;
    rewrite ^/sitemap\.xml$ /data/sitemap.php;
    
    location @handler {
        rewrite ^/(.*)$ /data/engine.php?a=$1;
    }
    
    location / {
        try_files $uri $uri/ @handler;
    }
    
    location ~ \.php$ {
        try_files $uri =404;
        
        # Тут нужно добавить свои параметры fastcgi
    }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question