title: PRESTASHOP NGINX + REWRITE RULES
body: <p>I've being searching for a good solution for this combination and after following these:</p>
  
  <ol>
  <li><a href="http://www.phamviet.net/2012/06/03/prestashop-rewrite-url-on-nginx/" rel="nofollow noreferrer">http://www.phamviet.net/2012/06/03/prestashop-rewrite-url-on-nginx/</a></li>
  <li><a href="http://www.nginxtips.com/nginx-configuration-for-prestashop/" rel="nofollow noreferrer">Nginx configuration for Prestashop</a></li>
  <li><a href="http://www.prestashop.com/forums/topic/307168-prestashop-1562-rewrite-urls-over-nginx-install/?hl=%2Bnginx#entry1554501" rel="nofollow noreferrer">Prestashop 1.5.6.2 rewrite URLs over nginx install</a></li>
  </ol>
  
  <p>none of them seemed to work for me at all... so I started experimenting:</p>
  
  <p>After configuring SSL, CloudFlare, etc.... </p>
  
  <p>This is what I tried:</p>
  
  <pre><code>server {
    listen 80;
    server_name mysuperdomain.com www.mysuperdomain.com;
    rewrite ^ https://$server_name$request_uri? permanent;
  }
  
  server {
    # listen 80 deferred; # for Linux
    # listen 80 accept_filter=httpready; # for FreeBSD
    listen 443;
  
    # The host name to respond to
    server_name mysuperdomain.com *.mysuperdomain.com;
  
    # Path for static files
    root /sites/mysuperdomain.com/public;
  
    ssl on;
    ssl_certificate /etc/nginx/ssl/ssl.pem;
    ssl_certificate_key /etc/nginx/ssl/ssl.key;
  
    # Try static files first, then php
    index index.html index.htm index.php;
  
    # Specific logs for this vhost
    access_log /sites/mysuperdomain.com/log/log-access.log;
    error_log  /sites/mysuperdomain.com/log/log-error.log error;
  
    #Specify a charset
    charset utf-8;
  
    # Redirect needed to "hide" index.php
    location / {
      rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$1$2$3.jpg break;
      rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$1$2$3$4.jpg break;
      rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$1$2$3$4$5.jpg break;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$1$2$3$4$5$6.jpg break;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg break;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg break;
      rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg break;
      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/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg break;
      if (-e $request_filename){
          rewrite ^(.*)$ /index.php break;
      }
      try_files $uri $uri/ /index.php?q=$uri&amp;$args;
  }
  
  location /c {
      rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/$1$2$3.jpg break;
      rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/$1$2.jpg break;
  }
  location /images_ie {
      rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 break;
  }
  
  # Don't log robots.txt or favicon.ico files
  location ~* ^/(favicon.ico|robots.txt)$ {
      access_log off;
      log_not_found off;
  }
  # Custom 404 page
  error_page 404 /index.php?controller=404;
  
  location ~* ^.+.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|htm|html|js|css|mp3|swf|ico|flv|xml) {
      access_log off;
      expires 30d;
  }
  
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
  
      # With php5-cgi alone:
      # fastcgi_pass 127.0.0.1:9000;
      # With php5-fpm:
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_intercept_errors on;
      fastcgi_buffers 8 16k;
      fastcgi_buffer_size 32k;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
  }
  
  # Deny access to .htaccess
  location ~ /\.ht {
      deny all;
  }
  
  #PHPMYADMIN
  location /phpmyadmin {
   root /usr/share/;
   index index.php index.html index.htm;
   location ~ ^/phpmyadmin/(.+\.php)$ {
     try_files $uri =404;
     root /usr/share/;
     fastcgi_pass unix:/var/run/php5-fpm.sock;
     fastcgi_index index.php;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     include fastcgi_params;
  }
  location ~* ^/phpmyadmin/(.+\.(jpeg|jpg|png|css|gif|ico|js|html|xml|txt))$ {
     root /usr/share/;
  }
  }
  location /phpMyAdmin {
   rewrite ^/* /phpmyadmin last;
  }
  
  # Include the basic h5bp config set
  include h5bp/basic.conf;
  }
  </code></pre>
  
  <p>It seems to only work for categories but not for individual products pages and such.</p>
  
  <p>When you hit the main domain or go to the home page, it will download index.php instead of showing the home page.</p>
  
  <p>So a little bit of help would be amazing!</p>