S
S
Sergey Titov2016-01-12 02:21:39
Nginx
Sergey Titov, 2016-01-12 02:21:39

How to rewrite rewrite under nginx?

In general, my htaccess was as follows:

addDefaultCharset UTF-8

RewriteEngine On

RewriteRule ^([^/]*)/$ ?city=$1 [L]

RewriteRule ^([a-z\-]+)\/([a-z\-]+)?$ /index.php?city=$1&page=$2 [L]
RewriteRule ^users/profile/id(.*) /index.php?city=users&page=profile&id=$1 [NC,L]
RewriteRule ^users/profile/logout&(.*) /index.php?city=users&page=profile&act=logout&csrf=$1 [NC,L]
RewriteRule ^users/ajax&(.*) /index.php?city=users&page=ajax&action=$1 [NC,L]
RewriteRule ^([a-z\-]+)\/([a-z\-]+)\/([a-z\-]+)?$ /index.php?city=$1&page=$2&act=$3 [L]
RewriteRule ^([a-z\-]+)\/admin/edit-seanses/date=(.*)/film=(.*)/place=(.*)?$ /index.php?city=$1&page=admin&act=edit-seanses&date=$2&film=$3&place=$4 [L]
RewriteRule ^([a-z\-]+)\/date=(.*)$ /index.php?city=$1&date=$2 [L]
RewriteRule ^([a-z\-]+)\/([a-z\-]+)\/([a-z\-]+)\/id(.*)$ /index.php?city=$1&page=$2&act=$3&id=$4 [L]
RewriteRule ^([a-z\-]+)\/([a-z\-]+)\/([a-z\-]+)\/date=(.*)$ /index.php?city=$1&page=$2&act=$3&date=$4 [L]

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^/?(.*) http://%1/$1 [L,R=permanent]

We installed a server with nginx and the whole thing stopped working, tell me how to fix it :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
riot26, 2016-01-12
@riot26

htaccess converter for nginx

X
xmoonlight, 2016-01-12
@xmoonlight

charset utf-8;
rewrite ^/([^/]*)/$ /?city=$1 last;
rewrite ^/([a-z\-]+)\/([a-z\-]+)?$ /index.php?city=$1&page=$2 last;
rewrite ^/users/profile/id(.*) /index.php?city=users&page=profile&id=$1 last;
rewrite ^/users/profile/logout&(.*) /index.php?city=users&page=profile&act=logout&csrf=$1 last;
rewrite ^/users/ajax&(.*) /index.php?city=users&page=ajax&action=$1 last;
rewrite ^/([a-z\-]+)\/([a-z\-]+)\/([a-z\-]+)?$ /index.php?city=$1&page=$2&act=$3 last;
rewrite ^/([a-z\-]+)\/admin/edit-seanses/date=(.*)/film=(.*)/place=(.*)?$ /index.php?city=$1&page=admin&act=edit-seanses&date=$2&film=$3&place=$4 last;
rewrite ^/([a-z\-]+)\/date=(.*)$ /index.php?city=$1&date=$2 last;
rewrite ^/([a-z\-]+)\/([a-z\-]+)\/([a-z\-]+)\/id(.*)$ /index.php?city=$1&page=$2&act=$3&id=$4 last;
rewrite ^/([a-z\-]+)\/([a-z\-]+)\/([a-z\-]+)\/date=(.*)$ /index.php?city=$1&page=$2&act=$3&date=$4 last;
if ($http_host ~* "^www\.(.*)"){
  set $rule_10 1;
  set $bref_10_0 $1;
}
if ($rule_10 = "1"){
  rewrite ^/?(.*) http://${bref_10_0}/$1 permanent;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question