Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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...

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;
share|improve this question

try this (tested on Nginx 1.2.6 - Linux):

location /forum/photoplog/ {
   rewrite ^/forum/photoplog/(.+) /gallery/$1? permanent;
share|improve this answer
Thanks for helping out. Unfortunately I am still getting the 404 not found error message. – Joe Jan 25 '13 at 12:40
on your browser, the URL is changed from to ? If you get an 404 error, it's maybee due to your location /gallery (remove = and (.+) ) settings. Please post your nginx conf file. – 0xBAADF00D Jan 25 '13 at 20:26
It is somehow not working out. I have a lot of dynamic dead links from my old gallery in my webmaster tools error log. All dead URL's should only link to one single page since the content is not available anymore. (e.g. this link should change to just like all the other dynamic photoplog links should point to Check out my nginx.conf file at – Joe Jan 26 '13 at 9:55
your rewrite rules are not correct. when you do rewrite ^ / permanent; without $1, you lost everything. see my answer. or use location /forum/ { rewrite ^/forum/(.+) /$1? permanent; } – 0xBAADF00D Jan 26 '13 at 11:01
Thank you for trying to help me. It just won't work. Maybe I will have to upgrade the nginx server. – Joe Jan 28 '13 at 10:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.