Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable SEO URLs on multi stores and subdomains on OpenCart using Nginx

I am trying to get SEO URLs working across multi-stores in OpenCart.

I have two stores in the admin

http://www.shop.com (default)
http://m.shop.com

SEO URLs work for http://www.shop.com But they return a not_found.tpl (the 404 page) for the http://m.shop.com

This works however:

http://m.shop.com/index.php?route=product/product&path=68&product_id=52

SEO wise, it should be

/index.php?route=product/product&path=68&product_id=52

http://www.shop.com/product-title
http://m.shop.com/product-title (404 returned)

I am using NGINX. This is the config:

www.shop.com

server {
    server_name  www.shop.com;
    listen 80;
    root /var/www/www.shop.com/;
    index index.php index.html;
    location /image/data {
        autoindex on;
    }
    location / {
        try_files $uri @opencart;       
    }
    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

m.shop.com

server {
    server_name  m.shop.com;
    listen 80;
    root /var/www/www.shop.com/;
    index index.php index.html;
    location /image/data {
        autoindex on;
    }
    location / {
        try_files $uri @opencart;       
    }
    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
like image 216
TheBlackBenzKid Avatar asked May 07 '13 17:05

TheBlackBenzKid


1 Answers

I got this article and details from someone, in my company SEO and marketing team are using this tool..

From Setup SEO Full Friendly URLs on nginx on the XenForo forums:

It's actually really really simple.

Considering you have uploaded XenForo into the directory "community", just add this to your nginx config:

location /community/ {
            index  index.php index.html index.htm;
            try_files  $uri $uri/ /community/index.php?$uri&$args;
        }

While you are at it you might also want to add this to block external access to the folders "internal_data" and "library".

location ~ ^/community/(internal_data|library)/(.*)$ {
            internal;
        }

Restart nginx and enable Full Friendly URLs.

From Straight Forward Easy Instructions for Multi-Store Setup? on the Opencart forums:

The short version is:
create 2 demo sub domains
subA.domain.com
subB.domain.com
and "point" both sub domains to the same folder on your web host.
i.e. public_html/shop
Install opencart to the first sub domain and then go through the admin and add an extra store.

So you'll have Shop1 subA.domain.com and Shop2 subB.domain.com both running the same code.

Hope that makes sense.

like image 128
Javascript Coder Avatar answered Nov 15 '22 15:11

Javascript Coder