Dhafiq Sagara adalah orang bodoh yang tidak bisa apa-apa, tapi dia selalu berusaha untuk terus menjadi yang lebih baik. Rasa keingin-tahuannya sangat tinggi, selalu berusaha dan terus berusaha, trial dan error adalah prinsip belajarnya.

6 Mei 2011

How to Remove CMS ID from URL of PrestaShop version 1.2.5

After implementing the similar modification about how to remove the category and product id from URL of PrestaShop in my last two articles before this current one, now let’s try to remove also the CMS ID from URL of your PrestaShop. For instance, by default PrestaShop uses the URL for displaying CMS page like: /content/1-delivery instead of /content/delivery. I have successfully implemented the modification into PrestaShop version 1.2.5. It is recommended that you have also implemented the two similar modification about how to remove category id and how to remove product id from the URL of your PrestaShop.

  1. Make sure that you have already had the .htaccess file in your PrestaShop’s root directory, which has the content like the following:
    # .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]
    Actually, those content of .htaccess we get from the previous two modification from the two links above. You can generate this .htaccess file from admin panel at Tools tab, then choose Generators sub-tab, and follow the instructions carefully there. In this example above, I use prestashop1250 for the domain name. Please adjust it with yours.
  2. Add this following code after the last line of that code above:
    # 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]
    It meant that we will adjust the URL for 5 CMS pages: delivery, legal-notice, terms-and-conditions-of-use, about-us, and secure-payment. In other words, if you have more than 5 CMS pages, you have to define or add again your own CMS one by one into the .htaccess file.
  3. Open your /classes/Link.php file, and find this code:
    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);
    }
    
    then replace with this following code:
    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);
    }
    

Now you should have the URL without CMS ID in it.


Tidak ada komentar:

Posting Komentar