Post by danger » Thu May 05, 2016 12:24 pm

Nginx doesn't use .htaccess so rewrite rules must apparently be placed into the server block file, eg. /etc/nginx/sites-available/domain.com

I found a few configs thru google but none of them seem to make a difference, I always end up with a 404 when I click on a product when SEO URLs are enabled.

For example, one of the configurations I've tried is https://stackoverflow.com/questions/156 ... t-on-nginx

I can't seem to find anything within the past year so maybe the information is outdated for OpenCart 2.X?

I would appreciate any help or being pointed in the right direction with this.
Last edited by danger on Fri May 06, 2016 7:55 am, edited 1 time in total.

Newbie

Posts

Joined
Thu May 05, 2016 12:03 pm

Post by danger » Fri May 06, 2016 7:17 am

This worked :D

Code: Select all

# SEO URL Settings
  # Nginx configuration of OC htaccess
  location = /sitemap.xml {
    rewrite ^(.*)$ /index.php?route=feed/google_sitemap break; 
  } 

  location = /googlebase.xml {
    rewrite ^(.*)$ /index.php?route=feed/google_base break; 
  } 

  location / {
    # This try_files directive is used to enable SEO-friendly URLs for OpenCart
    try_files $uri $uri/ @opencart;
  }

  location @opencart {
    rewrite ^/(.+)$ /index.php?_route_=$1 last;
  }
  # End SEO settings
It didn't at first because I had a duplicate location / { from before.
sudo nginx -t is helpful ;)

Newbie

Posts

Joined
Thu May 05, 2016 12:03 pm

Post by Fengsheng » Sat May 25, 2019 3:25 pm

Great helpful answer, thank you and marked.

Newbie

Posts

Joined
Fri Apr 19, 2019 12:43 am
Who is online

Users browsing this forum: No registered users and 37 guests