Welcome! Log In Create A New Profile

Advanced

Can't get a rewrite rule right

Posted by 3zzy 
Can't get a rewrite rule right
August 26, 2016 04:06AM
Opencart has a strange URL structure:

http://domain.com/index.php?route=common/home
http://domain.com/index.php?route=account/register
http://domain.com/index.php?route=checkout/cart
http://domain.com/index.php?route=checkout/checkout

so basically I want to get rid of the string from `index.php?` to the first `/`.

[htaccess][1]:

RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ http://www.domain.com? [R=301,L]

[converted][2] to nginx:

location / {
if ($query_string ~ "^route=common/home$"){
rewrite ^/index\.php$ http://www.domain.com? redirect;
}
}

also tried:

location @opencart {
rewrite index.php\?route\=[^\/]*\/ / last;
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}

[1]: http://www.nixstudio.com/seo-friendly-url-opencart/
[2]: http://winginx.com/en/htaccess

but no joy, 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;
}
Re: Can't get a rewrite rule right
August 30, 2016 01:45AM
bump?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 62
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready