Forums

[resolved] mod_rewrite rule stopped working after 2.7 upgrade (4 posts)

  1. mdisanto
    Member
    Posted 5 months ago #

    I'm currently using pretty permalinks in the following format:
    /2009/06/29/sample-post/

    Previously I was using /archives/123.

    When I made the switch, I added a mod_rewrite rule to capture the old format and redirect. The .htaccess appears as follows:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule archives/(.*) /?p=$1 [R]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    Previously this would redirect the /archives/123 format to /?p=123, which would then be converted into the "pretty" format.

    This system broke when I upgraded to 2.7 for reasons I'm unable to figure out. When I browse manually to an /archives/123 url, I get a 404 error, but if I type in /?p=123 then it indeed gets converted to the pretty format. I'd like this to happen automatically obviously.

    Any idea why this stopped working or what I should do instead to achieve the same effect. Thanks!

  2. mdisanto
    Member
    Posted 5 months ago #

    I tried running the $wp_rewrite->non_wp_rules helper function to generate the rule and it did give me something a bit different than what I had, but still no luck.

    New .htaccess looks like

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^archives/(.*) //?p=$1 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

  3. Otto42
    Moderator
    Posted 5 months ago #

    Try [R,L] instead.

  4. mdisanto
    Member
    Posted 5 months ago #

    ah! it worked, thank you!!

Reply

You must log in to post.

About this Topic