WordPress.org

Forums

Apache rewrite rule not working in WP 2.6 (11 posts)

  1. distobj
    Member
    Posted 6 years ago #

    I had a rewrite rule that rewrote our old permalink structure (/YYYY/MM/DD/post-id) to the canonical ?p=post-id version. It didn't redirect, just rewrote.

    After upgrading to 2.6.3 however, that rewrite doesn't work. The old permalinks now give 404 errors. I've been able to fix it temporarily by changing the rewrite to a 302 redirect, but that's not the ideal solution because what the browsers gets now is *two* redirects; my 302 redirect to the ?p=post-id URL, and then a WordPress-provided 301 redirect to the new permalink.

    Does anybody know what I need to do to get internal rewriting working again? Thanks.

  2. It's hard to say what the problem is without knowing your specific rules. Post the contents of your .htaccess.

  3. distobj
    Member
    Posted 6 years ago #

    Thanks Otto!

    Here's the rewrite that used to work in 2.5, but no longer does after the upgrade to 2.6.3;

    RewriteEngine On
    RewriteBase /
    RewriteRule ^[0-9]{4}/[0-9]{2}/[0-9]{2}/00([0-9]*)/?$ /?p=$1 [L]

    what we've done for now is change the rule to use a 302 redirect;

    RewriteRule ^[0-9]{4}/[0-9]{2}/[0-9]{2}/00([0-9]*)/?$ /?p=$1 [R=302,L]

    That "works", but it results in not just the initial 302 redirect, but a subsequent 301 to the new permalink (as you probably know), so it's not a permanent fix (we hope!).

    Thanks again.

    Mark.

  4. Get rid of the [L] (and the R=302 for that matter), and make sure your rules comes before your normal WordPress .htaccess rules (the whole section, don't try to integrate them).

    A [L] (Last) modifier causes URL rewriting to stop. You don't want it to stop there, you want it to continue into WordPress with the modified URL.

  5. distobj
    Member
    Posted 6 years ago #

    Ok, thanks. Unfortunately, I made that change but the problem persists. Here's the full, revised .htaccess file;

    # Rewrite old custom permalink structure to canonical post-id form
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^[0-9]{4}/[0-9]{2}/[0-9]{2}/00([0-9]*)/?$ /?p=$1
    </IfModule>

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

    # END WordPress

  6. Hmm.. What happens if you simply take your rule out completely? Does it throw up a 404 page?

  7. distobj
    Member
    Posted 6 years ago #

    Yep, still a 404, which I'd expect because the old permalink structure was a proprietary one. Weird eh?

  8. distobj
    Member
    Posted 6 years ago #

    So fixing rewriting seems a dead end. 8-(

    Anybody else got any ideas about how I can avoid these two redirects? Two is two too many, but one would at least be an improvement. The only one-redirect solution that comes to mind is to generate the Redirect commands for all (~5000!) effected permalinks and stick those in .htaccess.

    Thoughts?

  9. I know a plugin exists that allows you to specify a secondary permalink string, which it uses to then redirect to the new permalinks, but I can't find the damn thing.

    Ahh, here it is: http://www.deanlee.cn/wordpress/permalinks-migration-plugin/

    No idea if that works with 2.6 or not, but it might do what you need.

  10. misieg772
    Member
    Posted 6 years ago #

    hi,

    same problem here - i described it in following thread:

    http://wordpress.org/support/topic/219282

    MAYBE SOME WP DEVELOPER ENLIGHTEN ME HOW CAN WE ADD CUSTOM REWRITES (NOT 301 REDIRECTS) TO HTACCESS THAT MAPS TO WORDPRESS PAGES/POST?????

    REGARDS

  11. garry12
    Member
    Posted 6 years ago #

    I'd also appreciate some help in the matter.. can anyone enlighten us?

Topic Closed

This topic has been closed to new replies.

About this Topic