Jump to content

Remove /fr/ en keep /en/ from my urls


ckarone

Recommended Posts

Hello

 

Everything is in the title, i started my shop in French only but now I need also an English version.

 

I used this tuto http://www.magavenue.com/blog/prestashop/supprimer-sous-dossier-fr-prestashop-14 but my French product urls give me a 404 error.

 

Not that the English version is ok end everything is ok if url rewritting is disable.

 

Have you an other solution to achive this ?

 

Sorry for made bad English.

 

Ckarone

Link to comment
Share on other sites

Yes, but where?

 

This is the modification in the generateHtaccess method

(This method generate the htaccess in the Tools.php classe)

 

if($language['iso_code'] =='fr'){
 foreach (Meta::getMetasByIdLang($language['id_lang']) as $key => $meta)
  if (!empty($meta['url_rewrite']) AND Validate::isLinkRewrite($meta['url_rewrite']))
   $tab['RewriteRule']['content']['^'.$meta['url_rewrite'].'$'] = $meta['page'].'.php?isolang='.$language['iso_code'].' [QSA,L]';
  elseif (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '')
   $tab['RewriteRule']['content']['^'.$default_meta[$key]['url_rewrite'].'$'] = $default_meta[$key]['page'].'.php?isolang='.$language['iso_code'].' [QSA,L]';
}else{
 foreach (Meta::getMetasByIdLang($language['id_lang']) as $key => $meta)
  if (!empty($meta['url_rewrite']) AND Validate::isLinkRewrite($meta['url_rewrite']))
   $tab['RewriteRule']['content']['^'.$language['iso_code'].'/'.$meta['url_rewrite'].'$'] = $meta['page'].'.php?isolang='.$language['iso_code'].' [QSA,L]';
  elseif (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '')
   $tab['RewriteRule']['content']['^'.$language['iso_code'].'/'.$default_meta[$key]['url_rewrite'].'$'] = $default_meta[$key]['page'].'.php?isolang='.$language['iso_code'].' [QSA,L]';
   $tab['RewriteRule']['content']['^'.$language['iso_code'].'/([^?&]*)'] = '$1?isolang='.$language['iso_code'].' [QSA,L]';
}

 

Before it was

foreach (Meta::getMetasByIdLang($language['id_lang']) as $key => $meta)
 if (!empty($meta['url_rewrite']) AND Validate::isLinkRewrite($meta['url_rewrite']))
  $tab['RewriteRule']['content']['^'.$language['iso_code'].'/'.$meta['url_rewrite'].'$'] = $meta['page'].'.php?isolang='.$language['iso_code'].' [QSA,L]';
 elseif (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '')
  $tab['RewriteRule']['content']['^'.$language['iso_code'].'/'.$default_meta[$key]['url_rewrite'].'$'] = $default_meta[$key]['page'].'.php?isolang='.$language['iso_code'].' [QSA,L]';
$tab['RewriteRule']['content']['^'.$language['iso_code'].'$'] = $language['iso_code'].'/ [QSA,L]';
$tab['RewriteRule']['content']['^'.$language['iso_code'].'/([^?&]*)$'] = '$1?isolang='.$language['iso_code'].' [QSA,L]';

 

Have you an idea?

Link to comment
Share on other sites

Hello,

 

Here is a part of my htaccess

...
RewriteRule ^([a-z]{2})/[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html /product.php?id_product=$2&isolang=$1 [QSA,L]
RewriteRule ^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*\.html /product.php?id_product=$2&isolang=$1 [QSA,L]
RewriteRule ^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+ /category.php?id_category=$2&isolang=$1&noredirect=1 [QSA,L]
RewriteRule ^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]* /category.php?id_category=$2&isolang=$1 [QSA,L]
RewriteRule ^([a-z]{2})/content/([0-9]+)\-[a-zA-Z0-9-]* /cms.php?isolang=$1&id_cms=$2 [QSA,L]
RewriteRule ^([a-z]{2})/content/category/([0-9]+)\-[a-zA-Z0-9-]* /cms.php?isolang=$1&id_cms_category=$2 [QSA,L]
RewriteRule ^([a-z]{2})/([0-9]+)__[a-zA-Z0-9-]* /supplier.php?isolang=$1&id_supplier=$2 [QSA,L]
RewriteRule ^([a-z]{2})/([0-9]+)_[a-zA-Z0-9-]* /manufacturer.php?isolang=$1&id_manufacturer=$2 [QSA,L]
RewriteRule ^([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /img/c/$1$2.jpg [L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]*\.html /product.php?id_product=$1 [QSA,L]
RewriteRule ^[a-zA-Z0-9-]*/([0-9]+)*\.html /product.php?id_product=$1 [QSA,L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+ /category.php?id_category=$1&noredirect=1 [QSA,L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]* /category.php?id_category=$1 [QSA,L]
RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*) /supplier.php?id_supplier=$1 [QSA,L]
RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*) /manufacturer.php?id_manufacturer=$1 [QSA,L]
RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*) /cms.php?id_cms=$1 [QSA,L]
RewriteRule ^content/category/([0-9]+)\-([a-zA-Z0-9-]*) /cms.php?id_cms_category=$1 [QSA,L]
RewriteRule ^lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html /product.php?id_product=$3&isolang=$1 [QSA,L]
RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)\.html /product.php?id_product=$2&isolang=$1 [QSA,L]
RewriteRule ^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*) /category.php?id_category=$2&isolang=$1 [QSA,L]
RewriteRule ^en/404-error$ /404.php?isolang=en [QSA,L]
RewriteRule ^en/address$ /address.php?isolang=en [QSA,L]
RewriteRule ^en/addresses$ /addresses.php?isolang=en [QSA,L]
RewriteRule ^en/authentication$ /authentication.php?isolang=en [QSA,L]
RewriteRule ^en/best-sales$ /best-sales.php?isolang=en [QSA,L]
RewriteRule ^en/cart$ /cart.php?isolang=en [QSA,L]
RewriteRule ^en/contact-us$ /contact-form.php?isolang=en [QSA,L]
RewriteRule ^en/discount$ /discount.php?isolang=en [QSA,L]

...

 

 

Thanks

 

Ckarone

Link to comment
Share on other sites

OK i found the htaccess problem

 

This is the wrong one :

RewriteRule ^[a-zA-Z0-9-]*/([0-9]+)*\.html /product.php?id_product=$1 [QSA,L]

 

This is the correct one :

RewriteRule ^[a-zA-Z0-9-]*/([0-9]+)*\-[a-zA-Z0-9-]*\.html /product.php?id_product=$1 [QSA,L]

 

I just have to find what's wrong in the generateHtaccess method modification.

 

Ckarone

Link to comment
Share on other sites

OK, here is the solution

 

In the Tools.php classe

Find this :

 $tab['RewriteRule']['content']['^[a-zA-Z0-9-]*/([0-9]+)*\.html'] = 'product.php?id_product=$1 [QSA,L]';

change by:

 $tab['RewriteRule']['content']['^[a-zA-Z0-9-]*/([0-9]+)-[a-zA-Z0-9-]*\.html'] = 'product.php?id_product=$1 [QSA,L]';

Now i have to found a solution to redirect /en/ folder to a sub domaine.

 

Have you a solution

Ckarone

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...