Opencart has this URL structure:
http://example.com/index.php?route=common/home
http://example.com/index.php?route=account/register
http://example.com/index.php?route=checkout/cart
http://example.com/index.php?route=checkout/checkout
... and I want to get rid of the string from index.php?route=
until the first /
, the regex for that is index.php\?route\=[^\/]*\/
, so the desired URL would be, for example, http://example.com/checkout
.
I tried:
location @opencart {
rewrite index.php\?route\=[^\/]*\/ / last;
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
and also tried:
location / {
if ($query_string ~ "^route=common/home$"){
rewrite ^/index\.php$ http://www.example.com? redirect;
}
}
... but no luck so far, I still see route=common/home
in the URLs.
This is my current Nginx configuration:
location / {
try_files $uri @opencart;
}
location @opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
deny all;
}
location ~ /\.ht {
deny all;
}
location /image/data {
autoindex on;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires max;
access_log off;
}