WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Permalink rewriting in 3.0 (36 posts)

  1. phil404
    Member
    Posted 3 years ago #

    Currently, I am using the "WordPress Category Archive" plugin with WP 2.9.2 in order to create an archive widget - much like the default Archive widget - that generates a list of years (linked) for posts within a specified category.

    WordPress Category Archive
    http://wordpress.org/extend/plugins/wp-category-archive/

    Permalink configuration:
    /%category%/%year%/%monthnum%/%postname%/

    This very same setup does not work in WP 3.0 when using anything but the default permalink option.

    Have the rewrite rules changed in WP 3.0?

    Thanks.

    -phil

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Not as far as I know but the plugin you're using may no longer be fully compatible.

  3. bsuneja
    Member
    Posted 3 years ago #

    Somewhat similar issue with permalinks in WP 3.0 RC.
    http://wordpress.org/support/topic/410466?replies=1

  4. RC 1, 2 or 3?

    What plugins are you running?

  5. phil404
    Member
    Posted 3 years ago #

    The plugin I am using is:

    WordPress Category Archive
    http://wordpress.org/extend/plugins/wp-category-archive/

    The issue described in my original post occurs in RC1, RC2, and RC3.

    Here's the query that WordPress chokes on:

    http://mysite.com/?m=2001&cat=13

    When permalinks is set to default, WordPress returns the proper posts. When I have permalinks set as noted in my original post, the page essentially refreshes. WordPress 3.0 appears unable to rewrite that query. WordPress 2.9.2 does not have this issue.

    -phil

  6. bsuneja
    Member
    Posted 3 years ago #

    RC3

    Fixed - it was the Redirection plug-in.

  7. phil404
    Member
    Posted 3 years ago #

    Glad YOUR problem has been resolved, bsuneja.

  8. Tagging this wp-category-archive so hopefully the plugin author will see, but this is likely something they need to fix :(

    I see you posted at http://www.prdream.com/wordpress/?page_id=1511 so ... there's some hope :( Sorry, man.

  9. phil404
    Member
    Posted 3 years ago #

    Thanks, Ipstenu.

    It's easy to dump this issue on the plugin, but obviously something has changed in WP between 2.9.2 and 3.0, to break the functionality. Specifically, something to do with how WordPress handles rewrites.

  10. Oh, I'm not denying that at all! A lot has changed (see http://codex.wordpress.org/Version_3.0 for a mostly complete list). But at the end of the day, WordPress works fine, and it's the plugin that has a problem.

    Which sucks. Now this could be an error on WP's side, sure, but most of the time these tend to be plugins making weird calls that they shouldn't have been in the first place.

    What happens when you turn off and turn back on the plugin? Does WP kick out any errors? What's in your .htaccess? Are you using SingleSite or MultiSite? Do you have any other plugins that modify htaccess/permalinks installed? Is the link generated the RIGHT link?

    Also, what version of the plugin are you using? The 1.3.0 version looks like it came out 10 days ago.

  11. phil404
    Member
    Posted 3 years ago #

    Thanks, Ipstenu. Your feedback is much appreciated.

    What happens when you turn off and turn back on the plugin?

    No change.

    Does WP kick out any errors?

    No error. With permalinks configured as follows:

    /%category%/%year%/%monthnum%/%postname%/

    the link generated by the plugin (/category-slug/yearnum/monthnum/) appears to confuse WordPress, which redirects back to the requesting page.

    When the permalinks option is set to default, the link generated by the plugin (?m=####&cat=###) returns a page with the correct content: all posts belonging to cat x for year ####.

    What's in your .htaccess?

    Pretty sure it's the standard WP generated .htaccess :

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    Are you using SingleSite or MultiSite?

    It's a single site installation.

    Do you have any other plugins that modify htaccess/permalinks installed?

    I do not.

    I would love to hear back from the plugin's author on this matter, but it appears the only way to contact him is via the comments on his plugin page. Until then, I'm merely trying to pinpoint the change in WP that renders the plugin incompatible.

    -phil

  12. Actually this line looks weird:

    RewriteRule ^index\.php$ - [L]

    This is my .htaccess (taken from a fresh install of WP).

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    I don't THINK this is the ish, but it can't hurt!

    What about other permalinks? Like the standard pretty ones? Or .. is this permalink set someplace other than the WP settings and somewhere in the plugin config?

  13. Hugh Mandeville
    Member
    Posted 3 years ago #

    Is there a way in WordPress 3.0 to show a page with posts for one specific category for a particular year and month with permalinks set?

    If permalinks is off, the WordPress Category Archive plugin creates a link in the format

    ?m=%year%%monthnum%&cat=%categoryid%

    This works fine for all the versions of WordPress I have tried: 2.8, 2.9.2, 3.0RC3, ...

    If permalinks are on and they contain the %category%, %year% and %monthnum%, the WordPress Category Archive plugin creates a link in the format

    /%category%/%year%/%monthnum%/

    This works in WordPress 2.9.2, but not in 3.0 RC3. In 3.0 it gets redirected to

    /category/%category%/

    WordPress provides functions for getting the permalink for a month (get_month_link) or a category (get_category_link), but nothing for both (get_category_month_link?). So the WordPress Category Archive plugin has to guess what it should set the link to.
    -Hugh

  14. phil404
    Member
    Posted 3 years ago #

    Hugh,

    Are you saying that WP 3.0 is missing a function that was present in earlier versions, resulting the failure of your plugin with certain permalink configurations?

  15. Hugh Mandeville
    Member
    Posted 3 years ago #

    No, WP3 isn't missing a function. WP3 seems to be handling a URL with %category% and %year% differently than WP2.9.2. Not sure if it is a mod_rewrite issue in .htaccess.

    With permalinks set to

    /%category%/%year%/%monthnum%/%postname%/

    going to the page

    /%category%/%year%/%monthnum%/

    on 2.9.2 will show a list of posts for the category for the specified year and month.
    On 3.0 it will redirect to

    /category/%category%/

    Which shows a category's post, but not filtered for a specific year and month. So there is probably something different in how the WordPress 3.0 code handles permalinks.

    I am not sure how to update the plugin to work with 3.0. Would require digging around in the WordPress code.

  16. phil404
    Member
    Posted 3 years ago #

    Thanks, Hugh. That was clarification I was seeking. Hopefully, someone is the know will provide you with the info you need to update the plugin for 3.0.

  17. Hugh Mandeville
    Member
    Posted 3 years ago #

    I looked at the WordPress 3.0 code. The behavior is caused by a change to how the redirect_canonical function handles categories, tags and taxonomies in wp-includes/canonical.php.

    I don't know the code well enough to know if this is a good fix, but I moved a section of the 3.0 code that deals with taxonomy to inside the is_tax() if block, and things seem to work fine now.

    The original 3.0 code looks like:

    if ( is_category() ) {
         $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
    } elseif ( is_tag() ) {
        $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
    } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
        $tax = get_taxonomy( $obj->taxonomy );
        if ( false !== $tax->query_var)
            $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
        else
            $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
    }
    $tax_url = parse_url($tax_url);
    if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
        parse_str($tax_url['query'], $query_vars);
        $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
    } else { // Taxonomy is accessable via a "pretty-URL"
        $redirect['path'] = $tax_url['path'];
    }

    I updated the bottom chunk of code that deals with tax_url to be inside the elseif (is_tax()) block.

    if ( is_category() ) {
         $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']);
    } elseif ( is_tag() ) {
        $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']);
    } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too:
        $tax = get_taxonomy( $obj->taxonomy );
        if ( false !== $tax->query_var)
            $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
        else
            $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']);
        $tax_url = parse_url($tax_url);
         if ( ! empty($tax_url['query']) ) { // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
            parse_str($tax_url['query'], $query_vars);
            $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
        } else { // Taxonomy is accessable via a "pretty-URL"
            $redirect['path'] = $tax_url['path'];
        }
    }

    So I think WordPress needs to be updated and not the plugin.

  18. phil404
    Member
    Posted 3 years ago #

    Thanks, Hugh! I'm going to give your fix a try.

  19. phil404
    Member
    Posted 3 years ago #

    Well, I implemented your code fix and all seems to be working well. Thanks again, Hugh. You saved us having to go with an ugly work-around.

  20. Philip Arthur Moore
    WordPress.com Theme Wrangler
    Posted 3 years ago #

    Whew. HUGE sigh of relief. I faced the exact same problem as Phil (I think our name is cursed right now) and implemented Hugh's solution. It worked beautifully. Thanks a ton.

  21. phil404
    Member
    Posted 3 years ago #

    Resolved with WP 3.0.1.

  22. audreycolette
    Member
    Posted 3 years ago #

    Um, it looks to me as if there is still a problem with the rewrite in WP 3.0.1. (see other threads on permalinks) Pretty links to pages don't work. Should I use Hugh's solution even if I'm using WP 3.0.1?

  23. fongandrew
    Member
    Posted 3 years ago #

    Using 3.0.1 and it's still not working. Without changing any code, the query ?m=2010&cat=4 redirects to the archive page for category 4 (but not any specific month or year).

    Using the change Hugh suggested, the query ?m=2010&cat=4 redirects to the archive page for the year 2010 (but shows all categories).

    This only applies when using the non-default permalink structure of course.

    Ideas?

  24. sarah semark
    Member
    Posted 3 years ago #

    I'm having this issue too with a website I'm in the midst of developing. I'm using the most recent version of WP, with permalinks set, but the links output as m=2011&cat=3 and redirect to a refresh of the page. I've also noticed it's only generating a single year in the list, but that might be another issue altogether.

    Has anyone ascertained a fix for this, or perhaps has located a similar widget with better functionality?

    Cheers!

  25. fongandrew
    Member
    Posted 3 years ago #

    Figured out a quick fix. This works in WP 3.1.

    In wp-includes/canonical.php, find this line:

    } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) {

    Change it to this:

    } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && ! (count($_GET) == 2 && !empty($_GET['cat']) && !empty($_GET['m']))) {

    Explanation: The category archive plugin creates links to URLs like this: http://www.myblog.com?cat=5&m=200910 (this means, show me all posts in category 5 for Oct. 2009). When permalinks are on, the above conditional sends us into code that retries to rewrite the query in a "prettier" format.

    The changed conditional says that if the requested URL looks like a category archive URL, don't try to rewrite the query. That means your category archive URLs will be "ugly" but at least they work. And permalinks for regular posts will still be correct.

  26. playitusa
    Member
    Posted 3 years ago #

    I tried on my blog (www.playitusa.com) but it doesn't work.

  27. petra5
    Member
    Posted 3 years ago #

    I have the same problem. I am using WordPress 3.1 and I tried changing the code as per above, but it doesn't work. I need to have Permalinks on and Category archive to work once a specific month is clicked on. Any ideas anybody?

  28. proximity2008
    Member
    Posted 3 years ago #

    Bump!

    Any resolution to this in WordPress 3.1?

    Same problem as petra5.

  29. fongandrew
    Member
    Posted 3 years ago #

    At everyone who tried using my hack, what does your permalink structure look like?

  30. proximity2008
    Member
    Posted 3 years ago #

    Hi fongandrew,

    I applied your edit to linke 98 of canonical.php

    /%category%/%year%/%monthnum%/%post_id%/

    .htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    But yeah it is still stuck.

Topic Closed

This topic has been closed to new replies.

About this Topic