P
P
Pavel Mir2015-02-10 13:48:24
Nginx
Pavel Mir, 2015-02-10 13:48:24

How to set up a redirect to Nginx/Ghost?

There is a blog on the Egeya engine.
Links are in this format:

domain.com/?go=all/article-name-hello-world/
domain.com/?go=all/note-name-hi-kitty/
...

There is a desire to transfer the blog from Aegea to Ghost.
Everything is already set up, it remains to convert the old links.
So that when you enter a
domain.com/?go=all/note-name-hi-kitty/
redirect to work
domain.com/2014/12/23/note-name-hi-kitty/
, there are not so many links, even writing absolute paths is fine for me.
I tried to register in /etc/nginx/sites-enabled/ghost
rewrite ^/?go=all/(.*)$ domain.com/$1 permanent;
rewrite ^/\?go=all/(.*)$ domain.com/$1 permanent;
rewrite ~*/\?go=all/(.*)$ domain.com/$1 permanent;

Apparently the error is somewhere in the regular season, tk. there are messages in the logs
/hello-kitty/ HTTP/1.1", host: "domain.com"
2015/02/10 05:45:16 [notice] 2300#0: *73 "^/?go=all/(.*)$" does not match "/", client: 127.0.0.1, server: 127.0.0.1, request: "GET /?go=all/hello-kitty/ HTTP/1.1", host: "domain.com"
2015/02/10 05:45:16 [notice] 2300#0: *73 "^/\?go=all/(.*)$" does not match "/", client: 127.0.0.1, server: 127.0.0.1, request: "GET /?go=all/hello-kitty/ HTTP/1.1", host: "domain.com"
2015/02/10 05:45:16 [notice] 2300#0: *73 "~*/\?go=all/(.*)$" does not match "/", client: 127.0.0.1, server: 127.0.0.1, request: "GET /?go=all/hello-kitty/ HTTP/1.1", host: "domain.com"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2015-02-10
@Lynn

I would do like this:

map $arg_go $new_url {
  default "";
  all/note-name-hi-kitty/ /2014/12/23/note-name-hi-kitty/;
  all/article-name-hello-world/ /2014/01/01/article-name-hello-world/;
  # тут остальные ссылки
}

server {
  listen 80;
  server_name example.com;

  location = / {
    if ($new_url) {
      return 301 $new_url;
    }

    # тут какой-то конфиг для корня
  }

  # всё остальное

P
Pavel Mir, 2015-02-10
@facetheheat

Something has changed, but it doesn't work as it should yet:
the request
redirects to
/etc/nginx/sites-enabled/ghost

map $arg_go $new_url {
  default "";
  all/note-name-hi-kitty/ /2014/12/23/note-name-hi-kitty/;
  all/article-name-hello-world/ /2014/01/01/article-name-hello-world/;
  # тут остальные ссылки
}
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name 127.0.0.1;

    #redirect for old links
    location = / {
       if ($new_url) {
          return 301 $new_url;
       }
    }

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 10G;

    location / {
        proxy_pass http://localhost:2368;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question