从OpenCart中删除index.php?route =

时间:2012-12-13 00:08:58

标签: .htaccess seo opencart

我是.NET开发人员,但我的朋友打电话给我寻求支持。我使用.htaccess做了一些更改但是我已经损坏了SEO。

一切都以url上的“www”标签开头。我看到当我们不使用“www”并且我改变了.htaccess时我们得到了一些错误。我添加了重写规则并将mysite.com重定向到www.mysite .com。我们的问题已经解决但现在又出现了另一个问题。

我们正在使用Opencart - SEO并启用它。我们的产品似乎是

http://www.mysite.com/epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html

当我们到达www。

但如果我删除网址上的“www”标记,则好像是

http://www.mysite.com/index.php?_route_=epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html

它破坏了SEO。

我希望看到第二个像第一个网址。

我尝试过使用seo_url.php,.htaccess,但它不会改变任何内容。

我也试过Remove index.php?route=common/home from OpenCart的解决方案,但这对我没用。

现在我的seo_url.php是默认的,我收回了我的更改。我的.htaccess是

# 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]

在我发疯之前请帮助我。我花了3个小时。

谢谢大家, 问候

3 个答案:

答案 0 :(得分:0)

试试吧..

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

答案 1 :(得分:0)

老问题我知道,但也许有人会发现它有用:如果你更改HTACCESS规则,SEO网址中断的原因是它们依赖_route_来澄清"是的这是一个请求干净的网址,不是它的标准路线"。

如果您更改了HTACCESS中的index.php?_route_=,则还必须更改_route_中的/catalog/controller/common/seo_url.php IF条件。如果你这样做,可能会非常困难,首先在测试商店试试。

除了你在日志或分析日志之类的东西之外,什么都不应该看到_route_,因为它是一个蒙面实用程序uri。如果你看到真正的人类正在询问链接是什么,那么就采取行动。否则,最好离开它。

答案 2 :(得分:0)

也有同样的问题,我发现的任何问题都不能解决我的问题。但!我记得我也与Laravel一起工作,并且在此引擎中运行良好的url路径。不要问为什么将OpenCart与Laravel关联。因此,我在系统->设置->服务器中启用了SEO单选按钮,您也可以将其禁用,因为我认为站点工作没有差异。

此解决方案由以下几部分组成:

1。。在您的根文件夹中,用下一个快照替换 .htaccess 文件内容:

<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。。转到 /system/library/url.php 并找到link方法并将其替换为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 .= '&amp;' . http_build_query($args);
    } else {
      $url .= str_replace('&', '&amp;', '&' . ltrim($args, '&'));
    }
  }

  foreach ($this->rewrite as $rewrite) {
    $url = $rewrite->rewrite($url);
  }

  $url = str_replace('index.php?route=', '', $url);

  return $url; 
}

由于您更改了根文件夹中的 .htaccess 并更改了网址生成方法,因此您还需要记住有关管理部分的信息。如果您在admin中看到漂亮的url,只需将.htaccess从根文件夹复制到/ admin文件夹

如果要在管理员端保存原始网址,则必须稍作更改link方法,然后执行下一个操作:

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 .= '&amp;' . http_build_query($args);
    } else {
      $url .= str_replace('&', '&amp;', '&' . 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; 
}

结果:

之前

http://YOUR_SITE/index.php?route=product/product&product_id=52

之后

http://YOUR_SITE/product/product&product_id=52

之前

http://YOUR_SITE/index.php?route=account/login

之后

http://YOUR_SITE/account/login

相关问题