O
O
Ockonal2015-09-19 15:52:58
Nginx
Ockonal, 2015-09-19 15:52:58

How to rewrite url router in nginx?

Hello, there is nginx + php-fpm and the task is to redirect links to this route:
http://example.com/page/...
Instead of the ellipsis, there will be full addresses of other sites. In this regard, the logic often breaks and nginx thinks that there are paths to local files. For example:

http://example.com/page/another.com/data/article.html

I need to run the index.php script and pass everything after /page/ as a query string.
Here are my config attempts, which all give 404s:
location ~ ^/page/ {
        #rewrite ^/page/(.*)$ /index.php?$1;

        set $url http://mysite.com.ua/index.php;
        proxy_pass $url;
    }

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

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question