Permanent redirection with regex after moving blog

Nick Pearson nick.pearson at gmail.com
Thu Aug 13 01:07:18 MSD 2009


Try:

location ^~ /weblog/ {
  rewrite  ^/weblog/(.*)  /blog/$1  permanent;
}

I believe there's also a way to use regex captures in the location.
I've not used this method yet, but I believe it's something like this:

location ~ ^/weblog/(.*) {
  rewrite  ^  /blog/$1  permanent;
}

On Wed, Aug 12, 2009 at 3:42 PM, miles<nginx-forum at nginx.us> wrote:
> I have moved my blog from /weblog to /blog. How can I redirect
> all requests for /weblog and its files to /blog?
>
> I have tried:
>
> location /weblog/ { rewrite ^ /blog/ permanent; }
>
> but that pushes all /weblog/ requests to the /blog/ index page,
> including /weblog/foo, /weblog/bar.html, etc.
>
> I have tried a number of regex expressions, but so far none
> has worked as expected. Could someone please help shed
> some light on this?
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,4895,4895#msg-4895
>
>
>





More information about the nginx mailing list