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.

I've got problems with simple SEO friendly redirect. Web page has changed and I'd like to redirect old uris to new ones. For example I'd like to redirect /contact to /contact.html

I've tried

location = /contact {
    rewrite ^ /contact.html permanent;
}

But it seems's that it doesn't work and Nginx keeps passing request to Zend front controller (PHP).

Here's my current configuration (without rewrites)

server {
    listen *:80;
    server_name www.domain1.com domain1.com domain2.com www.domain2.com;

    error_log /var/log/nginx/domain1.error.log notice;

    root /home/domain1/www/public/;

    client_max_body_size 22M;

    #domain redirect
    if ($host != 'www.domain1.com' ) {
        rewrite ^/(.*)$ http://www.domain1.com/$1 permanent;
    }

    location / {
        index index.php;
    }

    # html cache static content
    location ~* \.(js|css|rdf|xml|ico|txt|gif|jpg|png|jpeg|swf|eot|ttf|woff)$ {
        expires 30d;
    }

    rewrite /path1/(\w*)/\w*\.(\w*) /path2/$1.$2;

    #Zend front controller
    if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
        break;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9200;
        fastcgi_param SCRIPT_FILENAME /home/domain1/www/public$fastcgi_script_name;
        fastcgi_param APPLICATION_ENV production;
        include /etc/nginx/fastcgi_params;
    }
}
share|improve this question
    
There are a number of factors which could change the way you can fix this. Could you please provide your current server block for this host? –  Martin Fjordvald Jul 12 '11 at 12:58
    
My current config is included –  Daimon Jul 13 '11 at 11:23
add comment

1 Answer

I would do it easier and put it in the top of your / location

location / {
    rewrite  ^/contact$  /contact.html  permanent;

    ....
    ....
}
share|improve this answer
    
I tried but my config still redirects to index.php. I've included my current config in question –  Daimon Jul 13 '11 at 11:23
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.