nginx重定向不起作用

时间:2015-06-15 16:30:38

标签: redirect nginx

location / {rewrite ^/PS160/img/(.*)\.jpg$ /img/$1 permanent;}

我需要实现的是将http://domain.com/PS160/img/p/9/9/1/7/9/99179.jpg重定向到http://domain.com/img/p/9/9/1/7/9/99179.jpg

它的作用是重定向http://domain.com/PS160/img/p/9/9/1/7/9/img//PS160/img/p/9/9/1/7/9/img//PS160/img/p/9/9/1/7/9/img/PS160/img/p/9/9/1/7/9/img//PS160/img/p/9/9/1/7/9/img/... - 414 Request-URI Too Large

文件名中还有一些特定的单词:

location /img { rewrite ^/(.*)-thickbox\.(png|jpg)$ /$1.$2 redirect; }

它没有做任何事情:

http://www.domain.com/59229-thickbox/tommy-hilfiger-planbok.jpg - > http://www.domain.com/59229/tommy-hilfiger-planbok.jpg

http://www.domain.com/img/p/6/2/4/7/4/62474-thickbox.jpg - > http://www.domain.com/img/p/6/2/4/7/4/62474.jpg

这样做的正确方法是什么?

编辑:nginx congig文件:/etc/nginx/sites-available/nord-presta.ddns.me.vhost:

server {
        listen *:80;


        server_name nord-presta.ddns.me www.nord-presta.ddns.me www.nordbags.com nordbags.com www.nordwatches.com nordwatches.com www.nord-presta-watch.ddns.net nord-presta-watch.ddns.net www.nordoutlet.com nordoutlet.com;

        root   /var/www/nord-presta.ddns.me/web;

        if ($http_host = "nordbags.com") {
            rewrite ^ $scheme://www.nordbags.com$request_uri? permanent;
        }
        if ($http_host = "nordwatches.com") {
            rewrite ^ $scheme://www.nordwatches.com$request_uri? permanent;
        }
        if ($http_host = "nordoutlet.com") {
            rewrite ^ $scheme://www.nordoutlet.com$request_uri? permanent;
        }

        location /nordbags.com/ {
          rewrite ^nordbags.com/(.*)$ /$1 last;
          try_files $uri $uri/ /index.php?$args;
        }

        location /nordwatches.com/ {
          rewrite ^nordwatches.com/(.*)$ /$1 last;
          try_files $uri $uri/ /index.php?$args;
        }
#        location /nordoutlet.com/ {
#          rewrite ^nordoutlet.com/(.*)$ /$1 last;
#          try_files $uri $uri/ /index.php?$args;
#        }

        index index.html index.htm index.php index.cgi index.pl index.xhtml;
       rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
       rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg last;
       rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
       rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
       rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
       rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
       rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
       rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
       rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
       rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg last;
       rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
       rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 last;
       try_files $uri $uri/ /index.php$is_args$args;
       error_page 404 /index.php?controller=404;


        error_log /var/log/ispconfig/httpd/nord-presta.ddns.me/error.log;
        access_log /var/log/ispconfig/httpd/nord-presta.ddns.me/access.log combined;



    location /stats {

            index index.html index.php;
            auth_basic "Members Only";
            auth_basic_user_file /var/www/clients/client0/web1/web/stats/.htpasswd_stats;
        }

        location ^~ /awstats-icon {
            alias /usr/share/awstats/icon;
        }


        location  ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors off;

        }

 #       location /img { rewrite ^/(.*)-thickbox\.(png|jpg)$ /$1.$2 redirect; }
    location / { rewrite ^/(.*)-thickbox\.(.*)$ /$1-large\.(.*) redirect; }
        location ~* \.(gif)$ {
                  expires 2592000s;
        }
        location ~* \.(jpeg|jpg)$ {
                  expires 2592000s;
        }
        location ~* \.(png)$ {
                  expires 2592000s;
        }
        location ~* \.(css)$ {
                  expires 604800s;
        }
        location ~* \.(js|jsonp)$ {
                  expires 604800s;
        }
        location ~* \.(js)$ {
                  expires 604800s;
        }
        location ~* \.(ico)$ {
                  expires 31536000s;
        }



}

0 个答案:

没有答案