Jump to content

[Solved] Specific CMS URL Rewriting in 1.4.7


Recommended Posts

Hi everyone.

 

I am facing a problem while tring to rewrite some of my URLS in PrestaShop 1.4.7.

 

Here's the thing :

I'd like to have a page named http://www.mysite.com/page instead of http://mysite.com/content/184-page.

So, basically, I'd like to remove the "content" and the CMS id.

But I only need to do this in some specific pages, not on all the CMS pages.

 

I tried this rule in my .htaccess file :

RewriteRule ^page$ /content/184-page [L]

(This is a rule that works on non-Prestashop websites,obviously)

 

But it doesn't work and redirects http://www.mysite.com/page to http://mysite.com/content/184-page instead of rewriting the URL.

 

Does anyone have an idea as to how resolve this situation ? Are there some classes I need to override or should I keep pulling my hair trying to fix this in the .htacces file ?

 

Thanks in advance.

Edited by roberto06 (see edit history)
Link to comment
Share on other sites

Hi Clayton,

 

I took a look at the free modules and managed to implement the part that was useful to me into my website.

 

Here's the solution in case someone else needs it :

 

Create a file name Link.php in the override/classes folder, containing the following lines :

<?php
class Link extends LinkCore {
public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = NULL)
{
 $base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true));

 if (is_object($cms) && $cms->id != 184) // Classic CMS Page
 {
  return ($this->allow == 1) ?
($base.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/'.(int)($cms->id).'-'.$cms->link_rewrite) :
($base.__PS_BASE_URI__.'cms.php?id_cms='.(int)($cms->id));
 }

 if (is_object($cms) && $cms->id == 184) // Specific CMS Page
 {
  return ($this->allow == 1) ?
($base.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).$cms->link_rewrite) :
($base.__PS_BASE_URI__.'cms.php?id_cms='.(int)($cms->id));
 }

 if ($alias)
  return ($this->allow == 1) ? ($base.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/'.(int)($cms).'-'.$alias) :
  ($base.__PS_BASE_URI__.'cms.php?id_cms='.(int)($cms));
 return $base.__PS_BASE_URI__.'cms.php?id_cms='.(int)($cms);
}
}
?>

 

Then add the following line in the .htaccess file :

RewriteRule ^page$ /content/184-page [L]

 

And that worked !

 

(This rule only works if the id of the CMS page is 184 and its rewritten URL is "page", but it's easily adaptable to other situations)

 

Problem solved, thx Clayton for showing me the way.

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...