| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | Mark Forums Read | User manuals | Login |
x5 - Subdirectories for languages using htaccess rewrite | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
x5 - Subdirectories for languages using htaccess rewrite
On a previous x4 site I had something like the following set up with each language subdirectory using the files from the root of domain.com. ie just one install of X-cart for the 4 languages.
domain.com/en domain.com/es domain.com/it domain.com/fr I want to do the same with the new x5 site. If I add the following to the .htaccess file RewriteRule ^es/(.*) /$1 RewriteRule ^fr/(.*) /$1 RewriteRule ^it/(.*) /$1 I can access any pages from the root directory from the language subdirectories, for example domain.com/toys is available from domain.com/fr/toys and domain.com/es/toys, but the links themselves on the page are missing the language subdirectory. Where should I look to correct this?
__________________
Core version: 5.5.xx |
|||||||
#2
|
|||||||||
|
|||||||||
Re: x5 - Subdirectories for languages using htaccess rewrite
I believe that almost all places that render links in X-Cart 5 call the \XLite\Core\Handler::buildURL() method in the end.
So, you should somehow program your custom module to insert the current language into the URL here (or in other methods that call this method).
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#3
|
|||||||
|
|||||||
Re: x5 - Subdirectories for languages using htaccess rewrite
In the end I found I had to go to the top and in var/run/classes/XLiteAbstract.php
edit getShopURL Code:
to get the subdirectory to appear in links. This is just a test! I now have to incorporate the code here x5 set language from browser and make it into a module. There is one thing that doesn't work though.. when there's more than one category in the url (ie domain.com/es/toys/rc-toys) gives a page not found.
__________________
Core version: 5.5.xx |
|||||||
#4
|
|||||||
|
|||||||
Re: x5 - Subdirectories for languages using htaccess rewrite
I've got further with this.
Code:
and the relevant part of the htaccess file... Code:
I realised that getShopURL is used by everything to build the path so the above isn't very efficient in that the method is not just making the links have the correct path but making all the page contents have the wrong path which is then corrected by the first part of the htaccess file. Without the second part of the htaccess there was a problem with deeper directories. I need the have English in the root to match the current site. Any ideas or input welcome!
__________________
Core version: 5.5.xx |
|||||||
#5
|
|||||||
|
|||||||
Re: x5 - Subdirectories for languages using htaccess rewrite
I now have this working as a module with the following functionality
One install of X-cart English at the root of the domain (ie domain.com) Four other languages in subdirectories (ie domain.com/fr domain.com/de etc) Language displayed based on URL (better for SEO and linking in general) Override selection of language via normal x-cart language selector Cookie set to remember user's preference if they use the language selector. I've removed the detection based on user's browsers language The files are as follows: In htaccess: Code:
SetLanguageFromDir.php (sets the language based on URL but redirects if the cookie value differs) Code:
SetLanguageFromSelector.php (sets cookies and redirects) Code:
AddLanguageDirToLinks.php Code:
If anyone spots anything that can be replace with X-cart functions or constants let me know. I don't really like the http stuff I've used.
__________________
Core version: 5.5.xx |
|||||||
|
#6
|
|||||||||
|
|||||||||
Re: x5 - Subdirectories for languages using htaccess rewrite
I believe this will be a very useful module!
However, I'm not sure about the following things: 1. "return \XLite\Core\URLManager::getShopURL($url, $isSecure, $params);" I think you should use parent::getShopURL() there. 2. Changes to .htaccess I believe modules can't alter .htaccess, so the changes should be explained somewhere in the module description or documentation.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#7
|
|||||||
|
|||||||
Re: x5 - Subdirectories for languages using htaccess rewrite
Looks like most of this is in the core now. Just edit this line in config.php
Code:
__________________
Core version: 5.5.xx |
|||||||
#8
|
|||||||||
|
|||||||||
Re: x5 - Subdirectories for languages using htaccess rewrite
Quote:
That is correct, this is in the core now.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful Click here to learn how to apply patches X-Cart Extensions |
|||||||||
|
Thread Tools | Search this Thread |
|
|
|
|||
X-Cart forums © 2001-2020
|