Search

Is there a way to add a default redirect to the .htaccess file so if no langauge is specified in the URL it redirects to a default:

The language redirect event does this. If a user requests a page (with the event attached to it) without language part at the front the event redirects the user to

  1. set language in a cookie, if not set
  2. first matched language in the browser preferences, if not set
  3. first (default) language set in the preferences

Please let me know if it doesn’t work for you.

@newnomad Hm, I don’t understand what you are after… You don’t have to use 5 character language codes in the preferences of the extension, it works just fine with 2 character codes. I put in the support for 5 character codes and split the URL part to get separate language and region parameters to be able to serve e.g. different currencies for the same language.

Adding the event to my homepage works redirects to the default language. However hitting another page directly without language in URL returns a page not found (apache 404 rather than Symphony)

mysite.com/page-a returns apache 404 error mysite.com/en/page-a works fine

Thanks for your help, really appreciated.

Andy

@klaftertief

Yes those are great features, but let me clarify what could be better; When a visitors browser has its language set to;

en-ie

This means he speaks English, and lives in Ireland.
Now I have English text available and want to serve that to him. However, my English text gets filtered in the datasource by the $url-language param. Now this parameter is en-ie and since I don’t have an entry with a language node of en-ie but only one with en this visitor gets a 404 page.
If I want to circumvent this I would have to fill out all possible language codes in the preferences and in my entry in a field.
This is why I prefer to dumb down the extension to only working with 2 letter codes.

If it would support any langauge code from a datasource, instead of preferences, then it would be possible to use the language field with multiple selections.

However the best option would be if the core of the extension simply would match en-ie with en and keep the regions only in the params (for ea currency), but not in the url and not in the matching.

makes sense?

I think the above can be solved by filtering the DS with a regex, to only match the firts 2 letters of the param, wihtout changing the extension.
Ofcourse supported languages from a DS still woudl be a welcome change.

Is there a way of having the $url-language as a url param at the end of URL rather than part of the url? so http://www.mydomain.co.uk/home/?lang=en rathjer than http://www.mydomain.co.uk/en/home/ can this be altered in the htaccess at all?

@klaftertief

I am running into some mod-rewrite problems when adding rules, seems your extension might be at fault. Can you advise?

@newnomad I tried it with the additional remove www rule in your from your .htaccess example and it’s working fine, redirecting from http://www... to http://....

In your example .htaccess you named the rule wrongly force www, it does the opposite. So maybe it just seems to be not working because you’re testing the opposite direction?

@monoo2 You don’t need the extension/additional rewrite rules to append a lang-parameter to your url. You could try to remove the language redirect rewrite rules and modify the event of the extension in a way that it doesn’t redirect to a clean but to a dirty URL.

I prefer clean urls so will stick to as is! thank you for this awesome feature! These small improvements keep bringing me back to symphony time and time again! great work.. muchly appreciated!

Hi, I have a small feature request: Would it be possible to include the full language names in the XML block? So we would have something like this:

<language-redirect>
    <current-language-code language="en">en</current-language-code>
    <supported-language-codes>
        <item language="en" name="English">en</item>
        <item language="fr" name="Français">fr</item>
    </supported-language-codes>
</language-redirect>

To keep the XML consistent what other parts of Symphony are producing I would rather suggest something like

<language-redirect>
    <current-language handle="en">English</current-language>
    <supported-languages>
        <item handle="en">English</item>
        <item handle="fr">Français</item>
    </supported-languages>
</language-redirect>

agreed with @phoque

At the moment the extension doesn’t have a library of full language names. I’ll look into adding one, but I can’t promise any timeframe. There are some other things like generalized redirect rules and better .htaccess modification behaviour on my TODO list as well.

@klaftertief If you look at the Multilingual Field plugin there’s already one there, you could just knick it :P

I pushed some changes and the XML now looks like

    <language-redirect>
        <current-language handle="de">Deutsch</current-language>
        <supported-languages>
            <item handle="de">Deutsch</item>
            <item handle="en">English</item>
        </supported-languages>
    </language-redirect>

or with regions

    <language-redirect>
        <current-language handle="de-ch">Deutsch (Switzerland)</current-language>
        <supported-languages>
            <item handle="de-ch">Deutsch (Switzerland)</item>
            <item handle="en-au">English (Australia)</item>
        </supported-languages>
    </language-redirect>

Before the changes the language and region had separate attributes, thus the odd XML.

Now I have to think about some of newnomad’s (old) suggestions.

klaftertief,
Regarding giving the extenion the option to ignore regions, as discussed in the beginning of this thread, can’t you just modify the code along these lines, to ‘forget about regions’

 substr($getBrowserLanguages , 0, 2);

Ofcourse the regions can stay in the xml, but just not in the url-schema.

The region parameter is only set when there is a match in the first URL language part, e.g. en-au will set the region parameter to au. So dumbing down the logic removes the region not only from the URL but also from the XML.

Earlier you wrote

When a visitors browser has its language set to;
en-ie
This means he speaks English, and lives in Ireland.
Now I have English text available and want to serve that to him. However, my English text gets filtered in the datasource by the $url-language param. Now this parameter is en-ie and since I don’t have an entry with a language node of en-ie but only one with en this visitor gets a 404 page.

The $url-language param is not en-ie but just en. (If it is the former, it’s a bug.) So you should be able to filter your content as you want.

Independently, I’m thinking about improving the extension, so feedback is welcome. At the moment I don’t have the time to work on it, but this will change in the next couple of weeks.

Hello, i’m new with Symphony.. (also with xsml)

first: I followed the instructions of the symph. tutorials.. Creating pages, data sources and sections..

than I installed the Language Redirect extention, add some language codes (like en,nl,de) and I added the Event to a page. After that i installed the Multilingual field extention. I created some multilingual fields in my section manager, and they appeared when i’m creating an “article”..

When I click in my navigation on a page where i applied the extention “language redirect” symphony adds an “en” to my url, that seems to work. But when i’m entering the page Symphony tells me “The page you requested does not exist.”

Is this normal? How can I fix that?

Hi dingdong,

could you tell a bit more about the errors you get, please? Like parameters, attached datasources, Symphony version etc.

When I click in my navigation on a page where i applied the extention “language redirect” symphony adds an “en” to my url, that seems to work. But when i’m entering the page Symphony tells me “The page you requested does not exist.”

So does /en/page/ work and just /page/ gives you the 404? Do you have a data source attached to the page that may redirect to the 404 page?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details