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.