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

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;

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

    root /home/domain1/www/public/;

    client_max_body_size 22M;

    #domain redirect
    if ($host != '' ) {
        rewrite ^/(.*)$$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;

    location ~ \.php$ {
        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

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

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.