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


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;

try this (tested on Nginx 1.2.6 - Linux):

location /forum/photoplog/ {
   rewrite ^/forum/photoplog/(.+) /gallery/$1? permanent;
  • 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 domain.com/forum/photoplog/file.php?n=1149&w=l to domain.com/gallery/file.php?n=1149&w=l ? 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 domain.com/forum/photoplog/file.php?n=1149&w=l should change to domain.com/gallery/ just like all the other dynamic photoplog links should point to domain.com/gallery/ Check out my nginx.conf file at pastebin.com/fuPN5uFY – 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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