WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Static home page 404 issue (54 posts)

  1. RavanH
    Member
    Posted 2 years ago #

    GREAT PROJECT ! (sorry for shouting, but it is ;) )

    However, I ran into an issue:

    I have a static page as homepage and when setting the language option 'Add language info to all URLS's including...' the site home page accessed via mysite.tld/ gets redirected to the static page URL without language info and then returns a 404 page. The home pages are only available via their respective URLs with language info in it.

    For example mysite.tld gets redirected to mysite.tld/home with a 404 while mysite.tld/en/home/ and mysite.tld/fr/accueil/ are listed in their respective language menus as home pages and can be accessed via those URLs just fine...

    Am I missing something here?

    http://wordpress.org/extend/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    I did introduce the ability to add the language code to all urls in 0.7. I didn't want but so many users want it ! And although I recommend not to use it, so many users go straight checking the option ;-)

    Well you discovered another bug... It does work if you hide the language code for the default language, but not if you uncheck this option.

    Will look into this...

  3. RavanH
    Member
    Posted 2 years ago #

    Hmmm... I see.

    The reason for checking the option is the fact that the site had been running another language plugin before so URLs with the language info in them had already been indexed by search engines. The site is relatively new and had little translations so there is no real problem unchecking that option again. URLs with the language info for the default language get redirected automatically to the correct url without the language info.

    Still, it would be nice if this could be resolved :)

    I've got other sites (using that other language plugin) that I might want to migrate to Polylang but they have been running much longer so the question of permalinks is much more relevant there. And I realize it might be a lot of extra work that has no direct visible impact but... It would be a REAL asset for those that would like to migrate from other language plugins if URLs would get redirected (with status 301?) depending on that setting, like for example:

    /en/news/ >> /news/ or /en/news/
    /fr/news/ >> /accueil/ or /fr/accueil/

    By the way, I might have run into a related issue with this static homepage (this time without this infamous option 'Add language info to all URLs' checked): My home pages get redirected correctly now but there are new 'hidden' pages. For instance, visitors coming to the main site URL mysite.tld/ with a Dutch browser get redirected to mysite.tld/welkom/ which is the static homepage but mysite.tld/nl/ will show another version: the front page listing posts instead of the static content... Same thing for all other languages on the site. Trying a URL for an undefined language like mysite.tld/de/ results in a 404 correctly.

    Complicated stuff.

  4. RavanH
    Member
    Posted 2 years ago #

    Marked thread as resolved since the upgrade to 7.2 did indeed fix it.

    With huge respect for great support :)

  5. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    A fix for the Error 404 has been included in 0.7.2. Just try it and tell me if it solves your issue.

    For instance, visitors coming to the main site URL mysite.tld/ with a Dutch browser get redirected to mysite.tld/welkom/ which is the static homepage but mysite.tld/nl/ will show another version: the front page listing posts instead of the static content...

    This is how Polylang currently works. In fact the language is a custom taxonomy. So when you browse mysite.tld/nl/, this is equivalent browsing mysite.tld/language/nl/ (you did choose to remove /language/) which is the custom taxonomy archive as defined by the WordPress core. So currently mysite.tld/nl/ and mysite.tld/page-for-posts-nl have the same content.

    You are not alone to request that mysite.tld/nl/ sends to the static front page instead of the list of posts. It's on the roadmap... However don't expect it for tomorrow. As you may have seen, the project has grown very quickly, so now I want to stabilize things a bit and take time to correct bugs before working on new features.

  6. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    You discovered the fix while I was writing the answer :)

  7. RavanH
    Member
    Posted 2 years ago #

    You are not alone to request that mysite.tld/nl/ sends to the static front page instead of the list of posts. It's on the roadmap... However don't expect it for tomorrow.

    Excellent, there is no hurry here. It's not a real problem unless you'd consider duplicate pages (the static blog pages and these alternative dynamic home pages) a real problem... I'm not to worried since there is no direct link to these alternative home pages.

    Question: why did you choose to direct a static home page to a permalink including the page slug? By default, WP does not do this... mysite.tld/ will show the page with slug /home/ if that is set to static home page, while mysite.tld/home/ will redirect to mysite.tld/

    Would it not be more logical, since you seem to have aimed for this with dynamic home pages, to show each static home page translation on their respective mysite.tld/ (for default language, unless that infamous 'Add language info to all URLs' option is checked), mysite.tld/fr/ and mysite.tld/en/ counterparts without the slugs?

    Thereby replacing these alternative hidden home pages at the same time ;)

  8. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    Because it was easy like this :D I just had to write a redirection to make it work.

    Moreover, one of my most important goal is to avoid (as much as possible) site breaking when the plugin is deactivated. mysite.tld/fr/ will be broken if the plugin is deactivated which is rather annoying for a 'homepage'. mysite/accueil/ will still exist if the plugin is deactivated :)

  9. RavanH
    Member
    Posted 2 years ago #

    OK, I see the point.

    Just to see what happens, I tried setting the slug for the french home page to /fr/ instead of /accueil/ ... I get that alternative dynamic home page listing all latest french posts all the time now ;)

    Another little glitch I noticed when using the 'Add language info to all URLs' option: the /robots.txt generation gets broken :(

    That option also breaks my own plugin XML & Google News Sitemap Feeds but that was to be expected. I'll have to find some way to make them compatible since Google News Sitemaps are language sensitive... as I did for qTranslate and xLanguage before. Hope I can bug you with questions about it some time ;)

  10. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    How do you generate the robots.txt ? I am rather old schooled and did that manually...

  11. RavanH
    Member
    Posted 2 years ago #

    You don't generate a robots.txt, WordPress does that for you :)

    Remove (rename) your static robots.txt for a minute and check out the URL again. There should be a dynamically generated robtos.txt (with disallow rules depending on your WP privacy settings) ... unless 'Add language info to all URLs' is checked.

  12. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    How could I imagine this ? Not even a generated file, but just a generated page ! Great... But now I have a bug to fix !

  13. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    This small modification should fix the robots.txt issue.
    Edit the file polylang.php at the line 342 (in 0.7.2) and replace:

    elseif ($is_archive || $is_comment_feed || $options['force_lang']) {

    by

    elseif ($is_archive || $is_comment_feed || ($options['force_lang'] && !strpos($rule, 'robots'))) {
  14. RavanH
    Member
    Posted 2 years ago #

    Excellent! :)

    By the way: can you tell me if there is a polylang variable during post loop which reflects the current posts language? Preferably in simple format for RSS use ( 'en' instead of 'en_US' ) ...

  15. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    I use this:

    reset(explode('_', get_locale()));

    It's standard WordPress and not linked to Polylang. Maybe I should provide a function which does this...

  16. RavanH
    Member
    Posted 2 years ago #

    OK, that might work... But only if get_locale() gets changed by Polylang depending on which post we are seeing in the loop. Is that the case?

  17. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    This is almost the only thing Polylang does ;-)

  18. RavanH
    Member
    Posted 2 years ago #

    Hmmm... that seems to return the default language rather than the language of the post in the loop.

    Take a look at the news sitemap -- created by my plugin, using using your code to get the language; it is actually a feed with special permalink -- on http://valentheze.fr/sitemap-news.xml ( or http://valentheze.fr/?feed=sitemap-news ) where the test post is set to FR and the default language is set to NL. In the source of the feed you can see the tag <news:language>nl</news:language> which is not the correct language for this post :(

  19. RavanH
    Member
    Posted 2 years ago #

    Correction: it does not seem to be the site default language in the Polylang settings but WPs own Settings > General > Site Language settings that is being returned there...

  20. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    There is a bug for feeds language since the beginning. The content is filtered by language but the language code is not the right one. I discovered that some days ago.

    The problem was because WordPress does use the option 'rss_language' instead of get_locale to set it and I was not aware of this... I know that it will change in WP 3.4.

    Before that, I decided to filter the option 'rss_language' to send the right language code. You can download the development version to test and tell me if it solves the issue.

  21. RavanH
    Member
    Posted 2 years ago #

    OK, will revert to get_option('rss_language') and test your dev version! :)

  22. RavanH
    Member
    Posted 2 years ago #

    UPDATE: using Polylang 0.8dev1 and standard get_option('rss_language') I get 'en' instead of the post language in my custom feed. Despite of the global site language (NL or FR) and the Polylang default language setting...

  23. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    Sorry... In fact I believed that the issue was coming from this get_option('rss_language') called instead of get_locale() in WordPress feeds.

    But your case is different. You are most probably looking for the language to soon. Since in most cases Polylang does not rely on language code in url to define the language, it is defined quite late, in the 'wp' hook.

  24. RavanH
    Member
    Posted 2 years ago #

    But the wp action is run right after the WP object is populated and well before the loop... Or am I msitaken? And in my template, I'm calling get_option('rss_language') from inside the loop.

    Anyway, even if it would show the correct value the first time, the question is if this value would get changed for each post in the loop anyway.

  25. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    Yes you are right, the wp action is called much before the loop. Here the language is set based on the request. For example, for a post, the language is set to the post's language.

    For archives and feeds, I need the language code to be included in the url (otherwhise, I could not know if you request archives in English or French...).

    I want to help. Could you explain what is your intended goal?

  26. RavanH
    Member
    Posted 2 years ago #

    OK, to explain: my plugin http://wordpress.org/extend/plugins/xml-sitemap-feed/ creates two custom feeds. One XML Sitemap (/sitemap.xml) and one Google News Sitemap (/sitemap-news.xml) based on two different feed templates. I have made the plugin compatible with qTranslate and xLanguage before but seem to have some trouble with Polylang.

    The standard XML Sitemap template generates a list of all posts and pages on the site with the proper markup for an xml sitemap. With Polylang enabled, the sitemap lists post/pages of different languages in the same feed. This works differently with the other multi-lingual plugins (where the language is part of the URL and so it creates /fr/sitemap.xml listing only French post for example) but that is not a problem. The sitemap protocol does NOT state only links to posts in the same language can be in one sitemap. It behaves the same as a normal feed with Polylang and all is fine.

    The problem arrises when generating the Google News sitemap. The protocol states a language tag needs to be there, reflecting the language of each post... With the other language plugins, several Google News sitemaps get created, one for each language, and using get_option('rss_language') generates the proper tag value for each post (always the same since all posts in each sitemap have the same language). But in Polylang, this method does not work out of the box as it did with the other language plugins ;(

    Fistly, get_option('rss_language') does not return the correct language and secondly, since with Polylang posts of different language will end up in the same feed, I need something that will change when running the loop, depending on the language set for each post.

    Is there a function in Polylang that does this already which I can call from withing my feed template inside the loop? Or a variable like $post->language; for example? Or a post meta value?

    Your help is greatly appreciated. The power of Polylang is its relative simplicity and low impact on resources and as such, a good alternative to other multi-lingual solutions for some of my multi-site installations. That same philosophy caused me to create the XML Sitemap plugin and it would be great if the two could be made to work together. :)

  27. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    I did write the plugin to make things easy and finally you believe it's more complex with Polylang than with other plugins :(

    Well I propose that we work in two times, first with the default permalink structure and second with url rewriting.

    The 'language' is a custom taxonomy in Polylang, so I guess that the correct way to get your sitemap in the right language is to look for: my-site/?feed=sitemap&lang=fr

    I made tests:

    my-site/?feed=sitemap&lang=fr is broken except if I set it as the default language in Polylang (don't understand why yet).

    However, I started debugging. Polylang does not modify the query (it sometimes do in some cases, but not here) and the program leaves my 'wp' filter with all posts and pages in the right language (whatever the language, whatever the choice for the default language). Up to here everything works as it should. Here is the SQL query:

    SELECT   wptest_posts.* FROM wptest_posts  INNER JOIN wptest_term_relationships ON (wptest_posts.ID = wptest_term_relationships.object_id) WHERE 1=1  AND ( wptest_term_relationships.term_taxonomy_id IN (4) ) AND wptest_posts.post_type IN ('post', 'page', 'attachment') AND (wptest_posts.post_status = 'publish' OR wptest_posts.post_author = 1 AND wptest_posts.post_status = 'private') GROUP BY wptest_posts.ID ORDER BY wptest_posts.post_modified DESC

    Here the language comes from: the term_taxonomy_id IN (4)

    So something breaks after may wp filter. I will go on debugging this...

    So I guess that when everything will work as expected, knowing the language of a post will not be useful. However there is a method: $polylang->get_post_language($post_id) returns the complete language object (in fact a term object). $polylang is global.

  28. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    I understand what happens. You get the right posts when you enter the loop but everything is broken by the line:

    if(!preg_match('/^' . preg_quote(get_bloginfo('url'), '/') . '/i', get_permalink())) continue;

    The reason for this is that Polylang filters get_bloginfo('url') to send you on the homepage in the right language. You expect it to be my-site/ but you receive my-site/?lang=fr except for the default language if you choose to hide the language for it :)

    If you replace get_bloginfo('url') by get_option('home') then everything works well :)

    Now we have to focus on rewrite rules

  29. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    You create your rewrite rules before Polylang filters them. I believe it's the best.

    Rewrite rules work perfect when adding the language code to all url. Otherwise Polylang left your rules unchanged. I can change this. I believe it's better than I do this rather than you (due to the options included in Polylang)

    Do you know if other plugins creating sitemaps are using the same rules than you ?

    'sitemap.xml$' => $wp_rewrite->index . '?feed=sitemap',
    'sitemap-news.xml$' => $wp_rewrite->index . '?feed=sitemap-news',
  30. RavanH
    Member
    Posted 2 years ago #

    Do you know if other plugins creating sitemaps are using the same rules than you ?

    Most other sitemap plugins create physical files, so there is no need for any rewrite rules. For others, I don't really know if they started using the same rules...

    But before you continue: I don't really see the need for seperate google news sitemaps per language. Using the $polylang->get_post_language($post_id) I should get the correct language per post and as long as the URL is correct ( with or without language code in it ) it should be just fine... Multiple google news sitemaps will only complicate things for the user. The fact that this is how it worked out of the box for qTranslate, does not mean it should be the same in Polylang.

    Or would you prefer adding the language code to the google news sitemap and xml sitemap URLs if that option is checked in Polylang?

    Adding the language string ?lang=fr will indeed cause the default value for get_option('rss_language') "en" to change. Par contre, it changes to "fr_FR"... This is not the correct language markup for RSS. It should become "fr". But in principle it works :)

    I adopted the get_option('home') method in the development version within that code snippet that is meant for verifying the domain ( there are plugins that allow external URLs as permalinks ) so it should work. All that is needed next is an extra filter in the feed tamplate for $polylang->get_post_language($post_id) to be inserted...

    @suivre

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags