Welcome! Log In Create A New Profile

Advanced

Re: rewrite url segment staging site and live site

Francis Daly
June 12, 2012 01:24PM
On Tue, Jun 12, 2012 at 10:47:10AM -0400, caleboconnell wrote:

Hi there,

> location /old {
> rewrite ^/old/? /new/$1 permanent;
> }

What do you think $1 is set to here?

(Usually, it is "the last thing matched". So usually, it is worth making
sure that you match something immediately before using it.)

> what I want:
> example.com/old/page1 --> example.com/new/page1
>
> what I get:
> example.com/old/page1 --> example.com/new

http://nginx.org/r/rewrite

"regex" can include things inside parentheses, which are then available
as ${number} in "replacement".

location /old/ {
rewrite ^/old/(.*) /new/$1 permanent;
}

will probably do what you want; but read about the question mark, in
case it matters.

> It's fine for now, but I don't know why the exact config would work
> different.

Usually, the same config works the same way. If you've found a case where
that isn't the case, it may be worth investigating. But it is potentially
the *whole* config that matters here, where you use $1 without showing
where it is set.

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

rewrite url segment staging site and live site

caleboconnell June 12, 2012 10:47AM

Re: rewrite url segment staging site and live site

Francis Daly June 12, 2012 01:24PM

Re: rewrite url segment staging site and live site

caleboconnell June 13, 2012 10:31AM

Re: rewrite url segment staging site and live site

B.R. June 13, 2012 12:02PM

Re: rewrite url segment staging site and live site

Francis Daly June 14, 2012 05:18PM

Re: rewrite url segment staging site and live site

caleboconnell June 13, 2012 12:31PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 163
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready