Beranda > PrestaShop > Bagaimana Menghilangkan ID CMS dari URL PrestaShop versi 1.2.5

Bagaimana Menghilangkan ID CMS dari URL PrestaShop versi 1.2.5

Setelah mengimplementasikan modifikasi yang sama mengenai bagaimana menghapus id kategori dan id produk dari URL pada dua artikel saya sebelum ini, sekarang mari kita mencoba menghapus juga ID CMS dari URL PrestaShop Anda. Sebagai contoh, secara standar PrestaShop menggunakan URL untuk menampilkan halaman CMS seperti ini: /content/1-delivery daripada yang seharusnya seperti ini: /content/delivery. Saya sudah berhasil mengimplementasikannya ke PrestaShop versi 1.2.5. Disarankan agar Anda juga mengimplementasikan dua modifikasi yang sama mengenai bagaimana menghapus id kategori and bagaimana menghapus id produk dari URL PrestaShop Anda.

  1. Pastikan bahwa Anda sudah memiliki berkas .htaccess di dalam direktori utama dari PrestaShop, dengan isi sebagai berikut:

    # .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
    # http://www.prestashop.com - http://www.prestashop.com/forums
     
    # URL rewriting module activation
    RewriteEngine on
     
    # URL rewriting rules
    RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /prestashop1250/img/p/$1-$2$3.jpg [L,E]
    RewriteRule ^([0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /prestashop1250/img/c/$1$2.jpg [L,E]
    RewriteRule ^lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /prestashop1250/product.php?id_product=$3&isolang=$1$5 [L,E]
    RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /prestashop1250/product.php?id_product=$2&isolang=$1$4 [L,E]
    RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /prestashop1250/category.php?id_category=$2&isolang=$1 [QSA,L,E]
    RewriteRule ^([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /prestashop1250/product.php?id_product=$2$4 [L,E]
    RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ /prestashop1250/product.php?id_product=$1$3 [L,E]
    RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /prestashop1250/category.php?id_category=$1 [QSA,L,E]
    RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /prestashop1250/cms.php?id_cms=$1 [QSA,L,E]
    RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*)(.*)$ /prestashop1250/supplier.php?id_supplier=$1$3 [QSA,L,E]
    RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*)(.*)$ /prestashop1250/manufacturer.php?id_manufacturer=$1$3 [QSA,L,E]
    RewriteRule ^lang-([a-z]{2})/(.*)$ /prestashop1250/$2?isolang=$1 [QSA,L,E]
     
    # Catch 404 errors
    ErrorDocument 404 /prestashop1250/404.php
     
    # Remove Category ID from URL. You have to modify also the /classes/Link.php file! Modified by Masino Sinaga, May 3, 2010
    RewriteRule ^accessories-ipod$ /prestashop1250/category.php?id_category=3 [QSA,L,E]
    RewriteRule ^music-ipods$ /prestashop1250/category.php?id_category=2 [QSA,L,E]
    RewriteRule ^laptops$ /prestashop1250/category.php?id_category=1 [QSA,L,E]
     
    # Remove Product ID from URL. You have to modify also the /classes/Link.php file! Modified by Masino Sinaga, May 4, 2010
    RewriteRule ^music-ipods/ipod-nano\.html(.*)$ product.php?id_product=1$1 [QSA,L,E]
    RewriteRule ^music-ipods/ipod-shuffle\.html(.*)$ product.php?id_product=2$1 [QSA,L,E]
    RewriteRule ^laptops/macbook-air\.html(.*)$ product.php?id_product=5$1 [QSA,L,E]
    RewriteRule ^laptops/macbook\.html(.*)$ product.php?id_product=6$1 [QSA,L,E]
    RewriteRule ^music-ipods/ipod-touch\.html(.*)$ product.php?id_product=7$1 [QSA,L,E]
    RewriteRule ^accessories-ipod/housse-portefeuille-en-cuir-belkin-pour-ipod-nano-noir-chocolat\.html(.*)$ product.php?id_product=8$1 [QSA,L,E]
    RewriteRule ^accessories-ipod/ecouteurs-a-isolation-sonore-shure-se210-blanc\.html(.*)$ product.php?id_product=9$1 [QSA,L,E]

    Sebenarnya, isi .htaccess tersebut kita dapatkan dari dua modifikasi sebelumnya melalui dua tautan di atas. Anda dapat membuat berkas .htaccess awal ini secara otomatis dari panel admin panel pada tab Tools, lalu pilih sub tab yang bernama Generators, dan ikuti petunjuk yang terdapat di sana dengan teliti. Dalam contoh di atas, saya menggunakan prestashop1250 sebagai nama domain. Silahkan sesuaikan dengan domain Anda.

  2. Tambahkan kode berikut setelah baris terakhir dari kode di atas:

    # Remove CMS ID from URL. You have to modify also the /classes/Link.php file! Modified by Masino Sinaga, May 5, 2010
    RewriteRule ^content/delivery$ cms.php?id_cms=1$1 [QSA,L,E]
    RewriteRule ^content/legal-notice$ cms.php?id_cms=2$1 [QSA,L,E]
    RewriteRule ^content/terms-and-conditions-of-use$ cms.php?id_cms=3$1 [QSA,L,E]
    RewriteRule ^content/about-us$ cms.php?id_cms=4$1 [QSA,L,E]
    RewriteRule ^content/secure-payment$ cms.php?id_cms=5$1 [QSA,L,E]

    Ini artinya bahwa kita akan menyesuaikan URL untuk 5 halaman CMS yaitu: delivery, legal-notice, terms-and-conditions-of-use, about-us, dan secure-payment. Dengan kata lain, jika Anda mempunyai lebih dari 5 halaman CMS, maka Anda harus menambahkan lagi CMS Anda sendiri satu per satu ke dalam berkas .htaccess tadi.

  3. Buka berkas /classes/Link.php Anda, dan temukan kode ini:

    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    
    	public function getCMSLink($cms, $alias = null)
    	{
    		if (is_object($cms))
    			return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.'content/'.intval($cms->id).'-'.$cms->link_rewrite) : 
    			(_PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms='.intval($cms->id));
    		if ($alias)
    			return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.'content/'.intval($cms).'-'.$alias) :
    			(_PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms='.intval($cms));
    		return _PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms='.intval($cms);
    	}

    lalu timpa dengan kode berikut:

    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    
    	public function getCMSLink($cms, $alias = null)
    	{
    		if (is_object($cms))
    			return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.'content/'/*.intval($cms->id).'-'*/.$cms->link_rewrite) : 
    			(_PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms='.intval($cms->id));
    		if ($alias)
    			return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.'content/'/*.intval($cms).'-'*/.$alias) :
    			(_PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms='.intval($cms));
    		return _PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms='.intval($cms);
    	}

Sekarang seharusnya Anda sudah memiliki URL tanpa ID CMS di dalamnya.

  • Share/Bookmark
1.099 kali dibaca Cetak Artikel Ini Cetak Artikel Ini