Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.