26

現在User SEO URL's、OpenCartAdminで[はい]に設定しています。

System -> Settings -> Store -> Server -> User SEO URL's

これまでのところ、すべてのタグとSEOリンクが機能しています。コマンドは目的の効果を発揮しました。

ただし、ホームページとその他のいくつかのリンクについては、削除するにはどうすればよいですか:

index.php?route = common / home

URLから?私は文字通りハードコードPHPファイルで検索と置換を行う必要があり、アップグレードのリスクがありますか、それとも別の方法がありますか?

(肥大化するパフォーマンスなし、つまりvQmodなどの貧弱なアマチュアツールはありません)

4

16 に答える 16

27

それを簡単に削除するには、で基本的な置換を行うことができます/catalog/controller/common/seo_url.php

探す:

return $link;

新しい行にそれを置く前に:

$link = str_replace('index.php?route=common/home', '', $link);

TheBlackBenzKidによる編集:完全なSEOが必要な場合は、上記の代わりに次の行を使用してください。

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

また、ストアの管理パネルでSEOURLがオンになっていることを確認してください。

于 2012-06-05T18:34:35.270 に答える
9

上記のVictorSchröderのソリューションはシンプルであるため、私は本当に気に入っています。ありがとう!誰かに役立つ場合に備えて、彼のコードmodに基づいてvQmodを作成しました。コードは次のとおりです。

<modification>

    <file name="system/library/url.php">
        <operation>
            <search position="before"><![CDATA[$url .= 'index.php?route=' . $route;]]></search>
            <add><![CDATA[
                if ('common/home' == $route) {
                    if ($args) {
                        $url .= '?' . str_replace('&', '&amp;', '&' . ltrim($args, '&'));
                    }
                } else {
            ]]></add>
        </operation>
        <operation>
            <search position="before"><![CDATA[foreach ($this->rewrite as $rewrite) {]]></search>
            <add><![CDATA[
                }
            ]]></add>
        </operation>
    </file>

    <file name="catalog/controller/common/seo_url.php">
        <operation>
            <search position="replace"><![CDATA[parse_str($url_info['query'], $data);]]></search>
            <add><![CDATA[
                if (isset($url_info['query'])) parse_str($url_info['query'], $data);
            ]]></add>
        </operation>
    </file>

</modification>
于 2013-08-09T03:24:03.713 に答える
8

以前の「解決策」は、SEO URL変換を攻撃しているため、間違っています。必要なのは、 OpenCart内でのURL生成を処理することです。

シンプルにしましょう。に移動し/system/library/url.phpて見てくださいpublic function link。関数を次のバージョンに置き換えます。

public function link($route, $args = '', $connection = 'NONSSL') {
    if ('NONSSL' == $connection) {
        $url = $this->url;
    } else {
        $url = $this->ssl;  
    }

    if ('common/home' == $route) {
        if ($args) {
            $url .= '?' . str_replace('&', '&amp;', '&' . ltrim($args, '&')); 
        }
    } else {
        $url .= 'index.php?route=' . $route;
        if ($args) {
            $url .= str_replace('&', '&amp;', '&' . ltrim($args, '&')); 
        }
    }

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

    return $url;
}

そのように単純です。これがOpenCartのコアにない理由は信じられません。

編集:

いくつかのテストを実行しましたが、SEO URLが有効になっている場合は/catalog/controller/common/seo_url.php、「未定義のインデックス」エラーを回避するために、で1回編集する必要があります。

内部public function rewriteで、次の行を置き換えます。

parse_str($url_info['query'], $data);

これで:

if (isset($url_info['query'])) parse_str($url_info['query'], $data);

今では本当に機能します。

于 2013-03-09T01:40:22.253 に答える
3

ステップ01.ストアサーバーの設定でUSESEOURLを有効にする

「システム」に移動し、「設定」をクリックします。変更したいストアを見つけて、右側の「編集」リンクをクリックします。最後に「サーバー」タブをクリックし、SEO URLの無線を「はい」に設定して、設定を保存します。

注:キーワードは自動的に作成されません。また、Apachemod_rewriteをオンにする必要があります。ほとんどのウェブホストはデフォルトでこれをオンにします。このチュートリアルのステップ3では、キーワードを追加する方法について説明します。

ステップ02..htaccessファイルの一部のコンテンツを変更して、ホームページをSEOURLフレンドリーにします

ホストのコントロールパネルに移動し、.htaccessファイルを編集します。このファイルを再表示するために非表示になっている場合があります。ウェブホストのコントロールパネルのファイルマネージャーをクリックし、[隠しファイルを表示]オプションにチェックマークを付けてから[移動]ボタンをクリックします。

.htaccessファイルを見つけたら、次の行を変更します。

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]

に:

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.yourwebsite.co.uk? [R=301,L]

上記の手順を実行すると、ホームページは次のようなものに変わります: http: //yourwebsite.com/index.php ?route=common/home次のようになります:http://yourwebsite.com

ステップ03.URLのSEOキーワードを手動で 入力する最後に、URLを書き換えたいすべてのページ、情報、製品、およびカテゴリにSEOキーワードを入力する必要があります。アイテムを編集および作成するときに、[データ]タブの下にSEOキーワードのフィールドがあります。

SEOキーワードを入力すると、URLが機能します。

これらのすべての指示に従うと、より高いランキング、トラフィックの増加、およびより多くの顧客のメリットを享受し始めることができます。

于 2016-09-18T20:23:26.027 に答える
2

したがって、私は1.5.5.1を使用していますが、この質問に対する回答は誰も私の問題を解決しませんでした。しかし、@ Jay Gilford@ TheBlackBenzKid、 @ rkaartikeyenからの回答を組み合わせて、完全に機能するソリューションを思いつきました。

@TheBlackBenzKidで示されているように、seoURLを有効にすることを忘れないでください。

コードの下に説明があります。

[php]
class ControllerCommonSeoUrl extends Controller {
    パブリック関数index(){
        //URLクラスに書き換えを追加します
        if($ this-> config-> get('config_seo_url')){
            $ this-> url-> addRewrite($ this);
        }

        //URLをデコードします
        if(isset($ this-> request-> get ['_ route_'])){
            $ components = explode('/'、$ this-> request-> get ['_ route_']);

            foreach($partsを$partとして){
                $ query = $ this-> db-> query( "SELECT*FROM"。DB_PREFIX。"url_aliasWHEREkeyword='"。$this->db-> escape($ part)。 "'");

                if($ query-> num_rows){
                    $ url = explode('='、$ query-> row ['query']);

                    if($ url [0] =='product_id'){
                        $ this-> request-> get ['product_id'] = $ url [1];
                    }

                    if($ url [0] =='category_id'){
                        if(!isset($ this-> request-> get ['path'])){
                            $ this-> request-> get ['path'] = $ url [1];
                        } そうしないと {
                            $ this-> request->get['path']。='_'。$ url [1];
                        }
                    }   

                    if($ url [0] =='manufacturer_id'){
                        $ this-> request-> get ['manufacturer_id'] = $ url [1];
                    }

                    if($ url [0] =='information_id'){
                        $ this-> request-> get ['information_id'] = $ url [1];
                    }   
                } そうしないと {
                    $ this-> request-> get ['route'] ='error / not_found';   
                }
            }

            if(isset($ this-> request-> get ['product_id'])){
                $ this-> request-> get ['route'] ='product / product';
            } elseif(isset($ this-> request-> get ['path'])){
                $ this-> request-> get ['route'] ='product / category';
            } elseif(isset($ this-> request-> get ['manufacturer_id'])){
                $ this-> request-> get ['route'] ='product / Manufacturer / info';
            } elseif(isset($ this-> request-> get ['information_id'])){
                $ this-> request-> get ['route']='情報/情報';
            }そうしないと {
                $ this-> request-> get ['route'] = $ this-> request-> get ['_ route_'];
            }

            if(isset($ this-> request-> get ['route'])){
                $ this-> forward($ this-> request-> get ['route']);を返します。
            }
        }
    }

    パブリック関数rewrite($ link){
        $ url_info = parse_url(str_replace('&'、'&'、$ link));

        $ url ='';

        $ data = array();

        parse_str($ url_info ['query']、$ data);

        foreach($ data as $ key => $ value){
            if(isset($ data ['route'])){
                if(($ data ['route'] =='product / product' && $ key =='product_id')||(($ data ['route'] =='product / Manufacturer / info' || $ data ['route'] =='product / product')&& $ key =='manufacturer_id')||($ data ['route'] =='information / information' && $ key =='information_id')){
                    $ query = $ this-> db-> query( "SELECT*FROM"。DB_PREFIX。"url_aliasWHERE` query`='"。$this->db-> escape($key。'='。(int)$価値) 。 "'");

                    if($ query-> num_rows){
                        $url。='/'。$ query-> row ['keyword'];

                        unset($ data [$ key]);
                    }                   
                } elseif($ key =='パス'){
                    $ category = explode('_'、$ value);

                    foreach($ category as $ category){
                        $ query = $ this-> db-> query( "SELECT*FROM"。DB_PREFIX。"url_aliasWHERE` query` ='category_id = "。(int)$category。"'");

                        if($ query-> num_rows){
                            $url。='/'。$ query-> row ['keyword'];
                        }                           
                    }

                    unset($ data [$ key]);
                }
            }
        }

        if($ url){
            unset($ data ['route']);

            $ query ='';

            if($ data){
                foreach($ data as $ key => $ value){
                    $query。='&'。$key。'='。$ value;
                }

                if($ query){
                    $ query ='?' 。トリム($ query、'&');
                }
            }

            $url_info['scheme']を返します。'://'。$url_info['host']。(isset($ url_info ['port'])?':'。$ url_info ['port']:'')。str_replace('/index.php'、''、$ url_info ['path'])。$url。$ query;
        } そうしないと {
            $ link = str_replace('index.php?route ='、''、$ link);
            $linkを返します。
        }
    }   
}

どうやら、@ Jay Gilford@TheBlackBenzKidは、ページに正しく書き込まれるURLの問題を解決しているようです。

113行目

$ link = str_replace('index.php?route ='、''、$ link);

しかし、コントローラーがページを見つけることができず、エラーページに戻るため、URLが壊れているようです。

38〜40行目

} そうしないと {
    $ this-> request-> get ['route'] ='error / not_found';   
}

@rkaartikeyenのソリューションは、現在のルートを要求されたルートに設定することでこの問題を解決します

51行目-53行目

そうしないと {
    $ this-> request-> get ['route'] = $ this-> request-> get ['_ route_'];
}
于 2013-03-07T14:16:52.580 に答える
2

ロゴのリンクを。に置き換えてみませんか<?php echo $base; ?>。ベースドメインへのリンクを作成し、を削除しindex.php?route=common/homeます。

于 2012-08-14T09:13:28.337 に答える
2

ジェイの解決策は私にはうまくいきません。編集した後、空白の画面が表示されます。だから私は新しいものを作りました:

前に行を置きます:

return $link;

後の代わりに:

public function rewrite($link) {
于 2013-03-03T15:20:17.183 に答える
1

私は遅れましたが、私の解決策は他の人にも役立つ可能性があります(Opencart 2.0.3.1でテスト済み):

MySQLコンソールを開き、次のクエリを実行します(データベース名をデータベース名に変更します)。

INSERT INTO `YOURDATABASE`.`url_alias` (`url_alias_id`, `query`, `keyword`) VALUES (NULL, 'common/home', ' ');

使い方:

トリックは、列「キーワード」に空白('')を追加することです。空の文字列('')を挿入すると、この回避策は機能せず、URLリライターは再びindex.php?route =common/を返します。家。

于 2015-07-05T14:26:06.533 に答える
1

私にとって、それを行う最も簡単な方法:

1-に移動/system/library/url.php

2-検索function link(

3-上記return $url;に次の行を入力します。

$url = str_replace('index.php?route=common/home', '', $url);
于 2020-05-09T23:29:32.657 に答える
1

OpenCart 3.x

まず、Webサイトのルートフォルダで、htaccess.txtの名前を.htaccessに変更します。

次に、[システム]>[設定]>[ストア]に移動します。編集。[サーバー]タブを開き、[ SEOURLを使用する]を[はい]に設定します。

次に、catalog / controller / startup/seo_url.phpを開きます

探す} elseif ($key == 'path') {

前に追加

} elseif ($key == 'route') {
  $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
 
  if ($query->num_rows && $query->row['keyword']) {
    $url .= '/' . $query->row['keyword'];
    unset($data[$key]);
  } else if ($data['route'] == "common/home") { 
    $url .= '/'; 
  } 

/index.php?route=common/homeになった/

そして今、あなたはアカウント/ログイン情報/連絡先のような構造を使用してデザイン>SEOURLでSEOURLを設定することができます。

于 2020-08-26T20:39:06.110 に答える
0

/catalog/controller/common/seo_url.php

ファイルを開き、以下のコードを置き換えます

<?php
class ControllerCommonSeoUrl extends Controller {
    public function index() {
        // Add rewrite to url class
        if ($this->config->get('config_seo_url')) {
            $this->url->addRewrite($this);
        }

        // Decode URL
        if (isset($this->request->get['_route_'])) {
            $parts = explode('/', $this->request->get['_route_']);

            foreach ($parts as $part) {

                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");

                if ($query->num_rows) {
                    $url = explode('=', $query->row['query']);

                    if ($url[0] == 'product_id') {
                        $this->request->get['product_id'] = $url[1];
                    }

                    if ($url[0] == 'category_id') {
                        if (!isset($this->request->get['path'])) {
                            $this->request->get['path'] = $url[1];
                        } else {
                            $this->request->get['path'] .= '_' . $url[1];
                        }
                    }   

                    if ($url[0] == 'manufacturer_id') {
                        $this->request->get['manufacturer_id'] = $url[1];
                    }

                    if ($url[0] == 'information_id') {
                        $this->request->get['information_id'] = $url[1];
                    }   
                } else {
                    $this->request->get['route'] = 'error/not_found';   
                }
            }

            if (isset($this->request->get['product_id'])) {
                $this->request->get['route'] = 'product/product';
            } elseif (isset($this->request->get['path'])) {
                $this->request->get['route'] = 'product/category';
            } elseif (isset($this->request->get['manufacturer_id'])) {
                $this->request->get['route'] = 'product/manufacturer/info';
            } elseif (isset($this->request->get['information_id'])) {
                $this->request->get['route'] = 'information/information';
            }else {
                $this->request->get['route'] = $this->request->get['_route_'];
            }

            if (isset($this->request->get['route'])) {
                return $this->forward($this->request->get['route']);
            }
        }
    }

    public function rewrite($link) {
        if ($this->config->get('config_seo_url')) {
            $url_data = parse_url(str_replace('&amp;', '&', $link));
            $url = ''; 

            $data = array();

            parse_str($url_data['query'], $data);
            foreach ($data as $key => $value) {

                if (isset($data['route'])) {
                    if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
                        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");

                        if ($query->num_rows) {
                            $url .= '/' . $query->row['keyword'];

                            unset($data[$key]);
                        }                   
                    } elseif ($key == 'path') {
                        $categories = explode('_', $value);

                        foreach ($categories as $category) {
                            $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");

                            if ($query->num_rows) {
                                $url .= '/' . $query->row['keyword'];
                            }                           
                        }

                        unset($data[$key]);
                    }else {
                        $url .= '/'.$value;
                    }
                }
            }

            if ($url) {
                unset($data['route']);

                $query = '';

                if ($data) {
                    foreach ($data as $key => $value) {
                        $query .= '&' . $key . '=' . $value;
                    }

                    if ($query) {
                        $query = '?' . trim($query, '&');
                    }
                }

                return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
            } else {
                return $link;
            }
        } else {
            return $link;
        }       
    }   
}
?>

------------------変更の場所-------------------------

パブリック関数index()に追加された以下の行もパブリック関数の書き換えです。

else {
this->request->get['route'] = $this->request->get['_route_'];
}

index()関数このように実行します

  1. htaccss "?route = $ 1"からクエリを取得します(例:URLはsite.com/shirtsのようになります)
  2. ルートはシャツです
  3. これで、関数は「シャツ」がurl_aliasテーブルで見つかった場合にそれが見つかった場合、それがurl_aliasテーブルからindex.php?categoryID=Valueのように変数を取得するようにチェックします。
  4. または、シャツのurl_aliasテーブルにレコードがない場合、そのチェックは、情報や製造元などの他のページであり、get変数を作成します。例index.php?route = information / informationまたはindex.php?route = product / Manufacturer/info。
  5. ただし、レイアウトにあるかどうかはチェックされません。だから私はこのindex.php?route=<ルート>のようなget変数にルートを設定するelseブロックにコードを追加しました
  6. したがって、index()関数では正常に機能します。同じように私は書き換え機能でやった。
于 2012-11-18T21:52:46.093 に答える
0

私はこれをhttp://www.antropy.co.uk/index.php/blog/one-quick-opencart-seo-tip-to-avoid-a-duplicate-home-page/でコードを削除するのに役立った私のホームページのために

于 2014-01-02T14:03:02.283 に答える
0

ファイル\system\ library \ response.phpで、パブリック関数output()の先頭に次の行を追加します

if (!defined('HTTP_CATALOG')) $this->output = str_replace(array('index.php?route=common/home', '?route=common/home'), '', $this->output);
于 2014-02-16T21:12:33.207 に答える
0

Opencart 3では、次のようなすべての醜いURLをリダイレクトする場合

index.php?route=common/home
index.php?route=account/register
index.php?route=product/product&path=244&product_id=481

あなたはあなたのきれいなURLをにAdmin -> Design -> SEO Urls似たものに追加する必要があります

ここに画像の説明を入力してください

次に、これを行います:catalog/controller/startup/seo_url.phpで、関数indexで、後に

if ($this->config->get('config_seo_url')) {
   $this->url->addRewrite($this);
}

これを追加

if (isset($this->request->get['route'])) {
    if (DOMAIN_ROOT . $this->request->server['REQUEST_URI'] != $this->rewrite(DOMAIN_ROOT . $this->request->server['REQUEST_URI'])) {
        $this->response->redirect($this->rewrite(DOMAIN_ROOT . $this->request->server['REQUEST_URI']));
    }
}
elseif (strpos($this->request->server['REQUEST_URI'], 'index') !== false) {
    $this->response->redirect(HTTPS_SERVER);
}

最後のステップを追加することはで定義するDOMAIN_ROOTことconfig.phpです

define('DOMAIN_ROOT', 'https://www.somedomain.org'); // no slash, no subfolder

それは私にとって非常にうまくいきます

于 2021-04-24T05:11:32.957 に答える
-1

このためにVQMODを作成しました。ここから無料でダウンロード:http ://www.opencart.com/index.php?route = extension / extension / info&extension_id = 14683

うまく機能します。

于 2013-12-12T15:50:53.390 に答える
-1

URLから削除するには、ファイルindex.php?route=を編集することをお勧めし.htaccessます。

これを追加するだけです:

RewriteCond %{THE_REQUEST} \ /index\.php\?_route_=?([^&\ ]*)
RewriteRule ^ /%1? [L,R]

何の問題もありません。RewriteEngineを有効にする必要があることを覚えておいてください。この行を探してください:RewriteEngine On。存在しない場合は、上記のコードの前にそれを過ぎてください。

于 2016-08-08T09:19:04.253 に答える