roberto06 Posted December 3, 2012 Share Posted December 3, 2012 (edited) 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 December 3, 2012 by roberto06 (see edit history) Link to comment Share on other sites More sharing options...
clayton29657 Posted December 3, 2012 Share Posted December 3, 2012 Hey Roberto06 The only way I know or seen how this worked was to buy the url rewrite module from add ons store to remove the page ID. You may also want to check free modules section as well. Cheers Clayton Link to comment Share on other sites More sharing options...
roberto06 Posted December 3, 2012 Author Share Posted December 3, 2012 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. 1 Link to comment Share on other sites More sharing options...
clayton29657 Posted December 3, 2012 Share Posted December 3, 2012 Just make sure that after removing any id that you test the url links. sometimes when removing a id an error will show. Just a heads up for you. Link to comment Share on other sites More sharing options...
roberto06 Posted December 3, 2012 Author Share Posted December 3, 2012 Yep, I am in the process of testing all the links (I have over 100), and so far, so good Link to comment Share on other sites More sharing options...
clayton29657 Posted December 3, 2012 Share Posted December 3, 2012 Nice good job! Link to comment Share on other sites More sharing options...
Recommended Posts