WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
404 errors with /%postname%/ permalinks (23 posts)

  1. fake946
    Member
    Posted 2 years ago #

    Hello,

    I'm using Polylang v0.8.5.
    When I use the default permalink type "http://localhost/wp2/?p=123", everything works fine. (Thank you for your work, btw.)

    But when I switch to the permalink type "http://localhost/wp2/example-article/", (http://localhost/wp2/%postname%/) I keep getting 404 errors.

    What am I doing wrong ?

    Thank you in advance for your answer,

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

  2. danielboros
    Member
    Posted 2 years ago #

    Hello Chouby,

    I have this problem with custom posts.
    I too have /%postname%/ permalinks.
    I'm getting 404 errors on all custom post type pages.

    For example, I have a custom post type called 'wallpapers', with a post called 'time-machine', but /wallpapers/time-machine/ throws a 404 error.

    WordPress itself does have a similar problem, but none of those solutions worked for me..

  3. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    Did you flush your rewrite rules ? (Settings-> permalinks : click on save changes).

    The normal url for an English post would be: /en/wallpapers/time-machine/ (except if English is the default language and you chose to hide the language code for it ?)

  4. danielboros
    Member
    Posted 2 years ago #

    Yes I've tried re-saving it a few times.

    However I do hide the language code - i give different names to all my posts and pages in different languages. This might not be a good idea but it seemed to work out fine up to this point..

    Thank you,
    Dabiel

  5. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    I wrote something wrong about the url. The language code is added only if the option "Add language information to all URL including posts, pages, categories and post tags" is checked.

    Yes, this is a limitation of the way Polylang works. You must have different names (or more exactly different slugs) for all posts and pages in different languages.

    Do you register the post type yourself or do you use a plugin ?

  6. danielboros
    Member
    Posted 2 years ago #

    I am keeping all my slugs different. I'd like to avoid adding language information to the url.

    I've registered my post types manually. Here's my code:

    register_post_type('wallpapers', array(
        'label' => __('Wallpapers'),
        'singular_label' => __('Wallpaper'),
        'public' => true,
    	'_builtin' => false,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'query_var' => false,
        'supports' => array('title', 'editor', 'trackbacks', 'custom-fields', 'thumbnail', 'comments'),
        'rewrite' => array('slug' => 'wallpapers')
    	));
  7. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    I copied pasted the above code in a function hooked to the init action. I don't get a 404 error but another bug (the language of the theme is always set to default whatever the language of the custom post type). The problem is linked to the line:

    'query_var' => false,

    which breaks the Polylang rewrite rules. Is there a specific reason for you not to set it to true ? Could you tell me if setting it to true (and then refresh your rewrite rules) solves your problem ?

    On my side, I will have to further look at this parameter and examine its consequences on rewrite rules.

  8. danielboros
    Member
    Posted 2 years ago #

    You are my hero. I don't know why I included the query_var, I guess I just copied it over from some sample code, while trying make things work..

    Anyway, I've simplified my function and now it works like a charm:

    register_post_type('wallpapers', array(
        'label' => __('Wallpapers'),
        'singular_label' => __('Wallpaper'),
        'public' => true,
    	'_builtin' => false,
        'supports' => array('title', 'editor', 'trackbacks', 'custom-fields', 'thumbnail', 'comments')
    	));

    I think I owe you a beer or two.

  9. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    Great. On my side, I found the reason for the bug. I will correct it with the next release.

  10. Mr_Scientist
    Member
    Posted 1 year ago #

    Hi all,

    This is a problem that I'm still encountering.

    The site I work on has a number of different parent > child categories across two languages. The URL structure I'm using is the 'postname' option. When categories are either edited or added the whole site gets 404s. At the moment I have to go to the permalinks setting screen and manually flush the rewrites rules. This isn't too bad when it comes to myself doing it, but for the other users is more complicated.

    Is there an elegant solution out there to this problem?

    I'm using Polylang v 0.9.2

  11. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Never got such problem. Did you test for a plugin or theme conflict? Does the problem occur only with %postname% permalink structure?

  12. Mr_Scientist
    Member
    Posted 1 year ago #

    Yes, it does only seem to occur when the permalinks are on. As for conflicts, this I'm unsure of, although I do know that the theme I'm developing on is available for translation.

  13. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    You should test first with WP + Polylang + Twenty Ten and then swithc your theme and add other plugins one by one to detect if there is a conflict.

  14. RRikesh
    Member
    Posted 1 year ago #

    If that may help, I got a similar problem some weeks back.

    I created a fresh .htaccess file (from this page of the Codex) and saved my permalinks again. It solved my issues.

    Don't forget to backup your .htaccess before :)

  15. holafandango
    Member
    Posted 1 year ago #

    Sorry for start a new chat... I have the same problem, all the entries, pages... goes to 404.

  16. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Did you try what has been suggested above?

    • Resave your permalinks first.
    • make test with WP + Polylang + Twenty Ten and then switch your theme and add other plugins one by one to detect if there is a conflict
  17. lukaszwiecek
    Member
    Posted 1 year ago #

    I have the same problem. Links /%postname%/ WordPress returns a 404 error

    WordPress 3.5, Polylang 0.9.8, Nginx server.

    1 - save the settings again friendly links
    2 - I checked on the skin Twenty Ten
    3 - I turned off all the other plug-ins

    The problem still exists.

    (sorry for my poor English;)

    Best regards
    Lukasz

  18. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    which link is 404?

  19. Nyanabhadra
    Member
    Posted 1 year ago #

    I have the same problem.

    It only happened to the root menu, but for the drop down menu is fine.

    Home is fine, but the rest of the menu return 404.
    I tried to save a new .htaccess
    I tried to deactivate most of the plugins that I have installed before Polylang.

    Actually, polylang works fine before, probably due to certain plugin have a new update or maybe other issue.

    Thank you so much for helping.

    smile,

  20. nabil_kadimi
    Member
    Posted 1 year ago #

    Resaving the permalinks solved the issue for me.

    Don't forget to clear cache if you have any caching plugin installed.

  21. Nyanabhadra
    Member
    Posted 1 year ago #

    Dear Nabil,

    Thank you so much.
    I have figured it out the problem long time ago.

    In the Settings of Polylang, I chosed this

    Keep /language/ in pretty permalinks. Example: http://eiab.eu/language/en/

    with smile from Germany!

  22. lukaszwiecek
    Member
    Posted 1 year ago #

    Hello,

    I found the cause of the problem. The functions.php file had code that changed the links to the authors of /author/ to /autor/

    add_action('init', 'author_rewrite');
    function author_rewrite() {
    	global $wp_rewrite;
    	$wp_rewrite->author_base = "autor";
    	$wp_rewrite->flush_rules();
    }

    After removing this code, everything works fine :)

    Can we somehow accept this change links to sites with plug Polylang authors?

    Best regards!

  23. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    I can't make anything with plugins and themes which use flush_rules in such a bad way. This function here is executed at every page load and one should *never* do this.
    http://codex.wordpress.org/Rewrite_API/flush_rules

    Just comment the line $wp_rewrite->flush_rules(); and you will be able to use the author base you want (go to settings->permalinks and click on 'save changes' to manually flush rules).

    If a plugin or a theme want to programmaticaly flus rules, it should make it at activation and deactivation.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic