View Single Post
  #4  
Old 07-22-2015, 06:41 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Re: x5 - Subdirectories for languages using htaccess rewrite

I've got further with this.

Code:
getShopURL now looks like this: public function getShopURL($url = '', $isSecure = null, array $params = array()) { //find current country code in URL $_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $segments = explode('/', substr($_SERVER['REQUEST_URI_PATH'], 1)); $lang_dir = $segments[0]; $store_language = $lang_dir; //code from url if (in_array($store_language, array('es','it','fr','de'))){ $url = $store_language.'/'.$url; } return \XLite\Core\URLManager::getShopURL($url, $isSecure, $params); }

and the relevant part of the htaccess file...

Code:
RewriteEngine on RewriteRule ^es/(.*) /$1 RewriteRule ^fr/(.*) /$1 RewriteRule ^de/(.*) /$1 RewriteRule ^it/(.*) /$1 # #BUG-772 Add HTTP_AUTHORIZATION header for fastCGI (need for XC\Qiwi) RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] RewriteRule (^|/)\. - [F] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^sitemap.xml(\?.+)?$ cart.php?target=sitemap [NC,L,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/../ RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(/?)(\.([_a-z0-9-]+))?$ cart.php?url=$5&last=$4&rest=$3&ext=$7 [NC,L,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/../ RewriteRule ^../((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(/?)(\.([_a-z0-9-]+))?$ cart.php?url=$5&last=$4&rest=$3&ext=$7 [NC,L,QSA] RewriteBase /

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
Reply With Quote