Nginx redirect dynamic page urls

nginxredirect

After changing the URL structure of my site I am getting a lot of 404 not found errors. Can some one point me into the right direction how to change certain page urls to a single page url using nginx.

Here are some examples of the pages which should permanently be redirected to the location domain.com/gallery/. Since I have more than 50 domain page urls which should be redirected to only one single page I have tried redirecting the dynamic urls by using (.+)

Sample Urls which should be redirected to one singe page…

domain.com/forum/photoplog/file.php?n=1149&w=l
domain.com/forum/photoplog/file.php?n=463&w=l
domain.com//forum/photoplog/file.php?n=464&w=l

My attempt to redirect all dynamic urls after /photoblog/ to a single page /gallery/, which did not work out.

location = /forum/photoplog/(.+) {
rewrite ^ /gallery/? permanent;
}

Best Answer

try this (tested on Nginx 1.2.6 - Linux):

location /forum/photoplog/ {
   rewrite ^/forum/photoplog/(.+) /gallery/$1? permanent;
}