A
A
Alexander Semikashev2015-07-07 20:06:26
Nginx
Alexander Semikashev, 2015-07-07 20:06:26

What is wrong with rewrite Nginx?

In general, I do this:

location / {
        root       "%hostdir%";
        index      index.php index.html index.htm;
        rewrite ^([^.]*[^/])$ $1/ permanent;

        rewrite ^/admin/$ index.php?type=admin;
    }

I open: www.site.ru/admin/ Error 404
I do this:
location = /admin/ {
        rewrite ^(.*)$ /index.php?type=admin;
    }

Works!
I add:
location = /admin/ {
        rewrite ^(.*)$ /index.php?type=admin;
        rewrite ^people$ /index.php?type=admin&module=people;
    }

I open: www.site.ru/admin/ Works I
open: www.site.ru/admin/people/ Error 404

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Filimonov, 2015-07-08
@verng95

It's all about slash.
Instead ,
you need it
rewrite ^/admin/$ /index.php?type=admin;,
and it will work. In your example, which is in location, there is just a slash.
As for the second rewrite (people), the slash at the end is missing. You need to do this:
In this case www.site.ru/admin/people/, it will work, BUT then it will not work without a slash. You can remove the $ , then it will work for any URLs that start with www.site.ru/admin/people, i.e. and for www.site.ru/admin/people/and for www.site.ru/admin/people-f////.
If you need for the version with and without a slash, then you can do this:

rewrite ^people/?$ /index.php?type=admin&module=people;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question