Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have been trying to redirect several single URLs to their new locations using Nginx. The URLs are from Blogger and are in the format: http://domain.com/yyyy/mm/slug.

For example, I have this: http://example.com/2013/04/chartjs-javascript-library-for-easy.html

I am using this Nginx rewrite to redirect it, but for some reason it doesn't work:

server {
     location ~ /([2012-2013]+)/.*/chartjs-javascript-library-for-easy.html {
                return 301 http://$server_name/resource/chart-js;
     }
}

I place this in /etc/nginx/conf.d/example.conf which is loaded inside /etc/nginx/nginx.conf

Can anybody tell me why it doesn't work? It was working sometime back. Am I messing up my regex?

EDIT:

For some reason, location /test redirects ok, but location /test/html doesn't. Any idea why?

share|improve this question
    
"/test redirects ok, but location /test/html doesn't" - is this a problem with ordering? Generally (regardless of platform), more specific rules should appear higher in the execution order. –  w3d Dec 27 '13 at 21:25
add comment

1 Answer

Note that [2012-2013] doesn't mean what you think it does :) [] is a character class, not a number class :)

Try location ~ ^/201[23]/.*/chartjs-javascript-library-for-easy.html

share|improve this answer
add comment

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.