I'm a .NET developer but my friend called me for support.I made some changes with .htaccess but i'm corrupted SEO.
Everything started with "www" tag on url.I see we get some errors when we are not using "www" and i'm changed .htaccess.I'm added rewrite rule and redirected mysite.com to www.mysite.com.Our problems are solved but now we have another problem.
We are using Opencart - SEO and it's enabled.Our products seems like
http://www.mysite.com/epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html
when we are reaching with www.
But if i remove "www" tag on url, it seems like
http://www.mysite.com/index.php?_route_=epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html
and it corrupt SEO.
I want to see second url like first one.
I'm tried play with seo_url.php , .htaccess but it doesn't change anyting.
I'm also tried solution on Remove index.php?route=common/home from OpenCart but it's not worked for me.
Now my seo_url.php is default, i get back my changes.And my .htaccess is
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ http://www.mysite.com? [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteRule ^(.*)$ index.php?_route_=$1 [L]
Please help me before i get crazy.I spend 3 hours for that.
Thank you for all, Greetings
Try This Its working for me using .htaccess.
RewriteCond %{THE_REQUEST} \ /index\.php\?_route_=?([^&\ ]*)
RewriteRule ^ /%1? [L,R]
Just try this..
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Old question i know but maybe someone would find it helpful: The reason SEO urls break if you change the HTACCESS rule is that they depend on _route_
for clarification that "yes this is a request for a clean url, no its not a standard route".
If you change index.php?_route_=
in the HTACCESS you must also change the _route_
IF conditionals in /catalog/controller/common/seo_url.php
. It may get heavily wonked out though if you do this, try it on test stores first.
Nothing should be seeing the _route_
except you in the logs or things like analytics logs since its a masked utility uri. If you see real humans are asking what the link is, then take action. Otherwise, its best to leave it.
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
来源:https://stackoverflow.com/questions/13850907/remove-index-phproute-from-opencart