multilingual site with nice urls (no index.php)

Author Message

Matthew Carroll

Wednesday 24 August 2005 5:52:53 pm

i have a functioning multilingual site in four languages (after some trying). i am using MatchOrder=uri and all pages on the site are accessible via, for example:

example.com/index.php/en/page (english)
example.com/index.php/fr/page (french)

and similarly the 'nice' urls also work - if i enter them by hand:

example.com/en/page
example.com/fr/page

...so the mod_rewrite rules are working correctly. however, i can't get ezpublish to drop the 'index.php' from its output. i tried overriding content/datatype/view/ezxmltags/link.tpl as suggested somewhere on this site - replacing ezurl with ezroot, and cleared the cache, but that didn't work.

what i want is remarkably similar to how the multilingual structure of http://ez.no functions, so it is possible, but i can't work out how to do it. does anyone know how to drop the 'index.php' using uri site access?

any help would be *really* gratefully appreciated :-)

thanks
matthew

http://carroll.org.uk

Marko Žmak

Saturday 22 October 2005 4:36:40 pm

In my experiance eZ doesn't provide that functionality. I have been searching for this either (and several other people too), and asking on the forum, but there was no success. I also proposed a improvement so that this could be achieved, but no results so far.
Although you could manually remove the index.php using the remove() operator:

http://ez.no/doc/ez_publish/technical_manual/3_6/reference/template_operators/strings/remove

since you know the length of "index.php", and the links made with ezurl begin with index.php. But this could require some work.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Alexandre Abric

Wednesday 26 October 2005 12:43:40 am

Of course it is possible to remove the index.php ffrom the URL ! You need to make a VirtualHost install of your eZ web site. Make a search on the forum or on ez.no and you'll find the answer.

Matthew Carroll

Wednesday 26 October 2005 12:28:13 pm

Alexandre, thanks, but you misunderstood the question.

You are correct that making a virtualhost install is well documented, but that isn't what I want (actually, wanted, I gave up and used a virtualhost install in the end.) The challenge is to create this:

example.com/en/page (siteaccess 'en')
example.com/fr/page (siteaccess 'fr')

The problem is that ezroot() strips the siteaccess name 'en'. Marko came up with an interesting solution, which is similar to the solution I eventually developed, and probably slightly easier. My solution was to use a define:

{def $btaccesstypename=$access_type.name scope="global"}

within pagelayout.tpl to give access to the siteaccess name within sub templates, and then put the following within the sub-template, for example:

<a href="/{$#btaccesstypename}{$node.url_alias|ezroot("no")}">blah blah</a>

Within the template, thereby reconstructing the url from the site access. This worked, and I was very close to using this on the final site. However, we have a central ez install on our server, and may want to have more ez-based sites using that same code base, for that reason I decided to use virtual host, with HostMatchType=map, for the simple reason that I didn't want to just have siteaccess names 'en' and 'es' but rather 'banterminator-en' and 'banterminator-es' etc, to enable for other 'en' and 'es' sites in future. Otherwise, I would have used the idea above.

Either way, even with ezroot() you still have to strip out all of the ezurl() references from every template, which is a nuisance - something as core as the url structure generated by ezurl() should be customisable somewhere.

Also, here is the script I used to do mass search and replace of ezurl with ezroot across templates. copy into a file, make executable:

#!/bin/sh

if [ $# -lt 3 ] ; then
echo -e "Wrong number of parameters."
echo -e "Usage:"
echo -e " renall 'filepat' findstring replacestring\n"
exit 1
fi

#echo $1 $2 $3
for i in `find . -name "$1" -exec grep -l "$2" {} \;`
do
mv "$i" "$i.sedsave"
sed "s/$2/$3/g" "$i.sedsave" > "$i"
echo $i
#rm "$i.sedsave"
done

At some point I will write up a full how to of my experiences getting a multilingual site working in ez, with more details of the above configuration that I didn't use in the end, since it's a good way to do it if you have a dedicated ez code base for your site.

http://carroll.org.uk

Matthew Carroll

Wednesday 26 October 2005 12:29:26 pm

I meant to say, if you're interested in the multilingual site, it is here:

http://www.banterminator.org

http://carroll.org.uk

Stéphane Cloutier

Wednesday 26 October 2005 5:35:37 pm

If I may ask you, and I know it does not relate to your problem, but how do you mirror each language using the language navigational links (at the top left)?

At whatever level and whatever language you are, it is possible on your site to see exactly the same page in another language. I have been trying to do the same, but without any success.

Qupanuaq - Snow bunting

Matthew Carroll

Wednesday 26 October 2005 8:08:54 pm

Hi Stéphane

It took me a while to find that answer too. I can't remember where I did, or I would link to it. The key to making this work is the following code:

$DesignKeys:used.url_alias

...which gives the url alias of the current page. Prefix that with the root uri of the other language site, and you get exactly what it is you are trying to achieve. Here is the full template block for my language switcher:

<div id="language-switcher">
<a href="{concat('http://www.banterminator.org/', $DesignKeys:used.url_alias)}">English</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a
href="{concat('http://es.banterminator.org/', $DesignKeys:used.url_alias)}">Espa&ntilde;ol</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a
href="{concat('http://fr.banterminator.org/', $DesignKeys:used.url_alias)}">En fran&ccedil;ais</a>
</div>

EDIT: the code above seems to end up with escape characters in it by mistake. Must be a forum problem. I pasted the code up here on my site:

http://carroll.org.uk/sandbox/ez/language-switcher.txt

Like I said, I will write up my experiences with setting up a multilingual ez site from scratch (no previous ez experience) at some point.

good luck!
matthew

http://carroll.org.uk

Alexandre Abric

Thursday 27 October 2005 12:48:24 am

Hi,

For all VirtualHosts setups I have made, I don't use the ezroot operator. I still use the ezurl operator, and all my urls look like :

mysite.com/en/page for english
mysite.com/fr/page for french

Do you have ForceVirtualHost=true in the site.ini settings ?

Leif Arne Storset

Tuesday 05 September 2006 2:05:55 am

I had the problem that eZ publish was inserting index.php into all my URIs. ForceVirtualHost=true solved the problem, and URIs now work perfectly.

Leif Arne Storset

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:12:17
Script start
Timing: Jan 18 2025 02:12:17
Module start 'layout'
Timing: Jan 18 2025 02:12:17
Module start 'content'
Timing: Jan 18 2025 02:12:17
Module end 'content'
Timing: Jan 18 2025 02:12:17
Script end

Main resources:

Total runtime0.6829 sec
Peak memory usage4,096.0000 KB
Database Queries81

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 589.2813152.6563
Module start 'layout' 0.00630.0031 741.937539.5078
Module start 'content' 0.00950.6720 781.4453755.6563
Module end 'content' 0.68150.0013 1,537.101624.1094
Script end 0.6828  1,561.2109 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4677160.0002
Check MTime0.00130.1943160.0001
Mysql Total
Database connection0.00080.122310.0008
Mysqli_queries0.598187.5847810.0074
Looping result0.00080.1102790.0000
Template Total0.649395.120.3247
Template load0.00190.281120.0010
Template processing0.647494.805920.3237
Template load and register function0.00020.024210.0002
states
state_id_array0.00150.216910.0015
state_identifier_array0.00160.230820.0008
Override
Cache load0.00180.2566670.0000
Sytem overhead
Fetch class attribute can translate value0.00050.071550.0001
Fetch class attribute name0.00110.1553130.0001
XML
Image XML parsing0.00570.833350.0011
class_abstraction
Instantiating content class attribute0.00000.0068160.0000
General
dbfile0.00660.9616360.0002
String conversion0.00000.001640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
20content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 50
 Number of unique templates used: 7

Time used to render debug report: 0.0004 secs