Nginx rewrite rules for Interspire Shopping Cart

It's been a while since I made my last post on this blog, but that's because I've been busy with work! Anyway, today I've chosen to publish a simple finding that I've come up with myself (not that it was any difficult anyway). It could be useful for people who want to run a web shop, particularly the excellent Interspire Shopping Cart. It comes with a set of rewrite rules for Apache to enable search-engine friendly URLs, but nothing for Nginx unfortunately.

Here is the Apache .htaccess file provided with Interspire Shopping Cart. I'm only pasting the section that we are interested in, in other words the Rewrite Module section:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php   
In order to achieve the same results in Nginx, you simply need to enable this location block:
        location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }
The try_files directive will attempt to serve the first parameter ($uri, the URI of the client request), then the second one ($uri + slash, could be a folder), but if neither is found, it will redirect the request to index.php and specify the requested URI as parameter in the URL together with the original arguments. It's as simple as that! The PHP scripts will handle the actual rewrites themselves.

Here is the full virtual host configuration which I used on a client's server:
    server {
        listen 80;
        server_name .website.com;
        root /var/www/website.com;
        index index.php;
       
        location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
    }
IMPORTANT NOTE: when you enable those rewrite rules in Nginx, Interspire does not automatically detect friendly URLs as being "available". So you need to go to your Interspire control panel, in the store settings, and force it to "Enable search-engine friendly URLs" instead of "Enable if available".

Enjoy!

Comments

Yumiko said…
THANK YOU SOOOOOOOOOOOOOOOOOOOOOO MUCH~ YOUR important notes really help me!!! I worked on the htaccess file two days...Nothing changes~ Thanks GOD!!!
MichaelA said…
Clement,

I've been trying for two days to get Interspire friendly URLs to work with nginx and I am still not successful.

Can you please elaborate on your post? In it, you quote a section of the .htaccess file and then you say to enable the location block. Finally, below you show an example virtual host configuration...

So, you are not actually modifying the .htaccess file, you are modifying the /usr/local/nginx/sites-available/mydomain.com virtual host file, correct? And you are leaving .htaccess unchanged?

I've tried your suggestion and I've tried the suggestion from Interspire's knowledge base. Nothing is working for me. Just get a "No input file specified." error from Interspire :(

If you can help, I would be grateful.

Thank you,

Michael
MichaelA said…
Figured it out. Yes, the file modified was the virtual host file. Additionally, Interspire must be installed in the root directory as defined in the Location section. For example, domain/public is OK, but /domain/public/shoppingcart will not work.

Michael
Thanks this is Great Wonderful information for shopping cart development.. Thanks.
Unknown said…
The Product is good. Have a look at ownmyshop.com Ecommerce Software E-Commerce Software Grocery Store Online Store Builder Website
Unknown said…
The Product is good. Have a look at ownmyshop.com Ecommerce Software E-Commerce Software Grocery Store Online Store Builder Website

Popular posts from this blog

Affiliate module for Interspire Shopping Cart

How to fix: Outlook on iOS/iPhone: "No Internet Connection"

Dealing with Nginx 400 Bad Request HTTP errors