0

We had a database corruption on our website, now we are building a new one.

However, we have thought off a different approach, we are migrating our old articles to a sub domain and building a new website with a better UI and architecture.

What I would like to do is redirect url from old website to the sub domain, with out in the format as this:

http://olddomain.com/foo/something

to

http://sub.olddomain.com/foo/something

and we want to keep the the olddomain to serve new content

http://oldomain.com/foo2/something

is this possible with Nginx


UPDATE

We have a set word based on which we want to redirect

we just want

 http://olddomain/foo/extrainfo

to redirect

http://sub.olddomain/foo/extra

when using the rewrite rule

/abc/ redirect permanent

we are having an issues that is a URL has word foo it's getting redirected to the new domain.

we just want http://olddomain/foo/ to redirect to http://sub.olddomain./foo/extra

not http://olddomain/abc/foo to http://sub.olddomain

4

2 回答 2

0

是的,这对 nginx 来说很简单。您只需在正确的位置/服务器块中放置一个重写规则:

server { 
    listen       80;
    server_name olddomain.com;
location ~/foo/ {
 rewrite ^ http://sub.olddomain.com$request_uri? permanent;
    }
  location / {
#serve new content
    }
}

server{
        listen       80;
        server_name sub.olddomain.com;
      location / {
    #serve old content
        }
}

我会支持之前的评论,您应该确保考虑到 SEO。

于 2013-10-16T19:30:15.047 回答
0

您需要在 URL 中添加一些内容来识别它是旧 URL 还是新 URL。如果你有东西,这很容易,我们可以回答这个问题。您给定的示例可以通过以下方式轻松解决:

location ~ ^/[a-z]+/[a-z]+$ {
  return 302 $scheme://sub.$server_name$request_uri;
}

location ~ ^/[a-z0-9]+/[a-z]$ {
  // serve new stuff
}

但不要忘记搜索引擎和其他机器人!如果您计划将来为新内容使用原始 URL,请不要重定向任何内容,只需将页面传送到相同的位置即可。

于 2013-10-16T18:44:38.803 回答