Remove index.php?route= from opencart
How to remove index.php?route= common issue from url bar for SEO url
I Also have the same problem and any that I found not solved my problem. But! I remember that I also working with Laravel and in this engine well working url path. Don't ask why I associated OpenCart with Laravel. So I enable SEO radio button in System -> Settings -> Server you also can disable it I don't see difference in the site work.
This solution consist from several part:
1. In your root folder replace .htaccess file content with next shapshot:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?route=$1 [L]
</IfModule>
2. Go to /system/library/url.php and find link
method and replace it with next:
public function link($route, $args = '', $secure = false) {
if ($this->ssl && $secure) {
$url = $this->ssl . 'index.php?route=' . $route;
} else {
$url = $this->url . 'index.php?route=' . $route;
}
if ($args) {
if (is_array($args)) {
$url .= '&' . http_build_query($args);
} else {
$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
}
}
foreach ($this->rewrite as $rewrite) {
$url = $rewrite->rewrite($url);
}
$url = str_replace('index.php?route=', '', $url);
return $url;
}
Since you changed .htaccess in root folder and change url generating method you also need remember about admin part. If you what see pretty url in admin just copy .htaccess from root folder to /admin folder.
If you want save orignal url in admin side you must little bit change link
method with next:
public function link($route, $args = '', $secure = false) {
if ($this->ssl && $secure) {
$url = $this->ssl . 'index.php?route=' . $route;
} else {
$url = $this->url . 'index.php?route=' . $route;
}
if ($args) {
if (is_array($args)) {
$url .= '&' . http_build_query($args);
} else {
$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
}
}
foreach ($this->rewrite as $rewrite) {
$url = $rewrite->rewrite($url);
}
// Skip admin path
if (strpos($_SERVER['REQUEST_URI'], '/admin') !== 0) {
$url = str_replace('index.php?route=', '', $url);
}
return $url;
}
Result:
Before
http://YOUR_SITE/index.php?route=product/product&product_id=52
After
http://YOUR_SITE/product/product&product_id=52
Before
http://YOUR_SITE/index.php?route=account/login
After
http://YOUR_SITE/account/login