rewrite rule for WordPress 3.3 permalinks is not working

Every since an upgrade to WordPress 3.3 URLs are not redirecting as they should.
Changed: domain.com/2010/10/postname/ to: domain.com/postname/

    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/[0-9]{4}/[0-9]{2}/(.+)$ /$1 [NC,R=301,L]

Related posts

Leave a Reply

3 comments

  1. The problem was due to the leading slash and not using $3

        RewriteEngine On
        RewriteBase /
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([0-9]{4})/([0-9]{1,2})/(.+)$ /$3 [NC,R=301,L]
    
  2. The last rule will never get applied if the previous rule matches. Assuming that the http://domain.com/2010/10/postname/ request doesn’t match a file or directory, the RewriteRule . /index.php [L] is going to rewrite the URI to /index.php thus it’ll never get to your rule. Try moving your rule up to the top, just below RewriteBase /, and duplicate the !-f/!-d conditions, so that it looks like this:

    RewriteBase /
    
    # for 301 redirect    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/[0-9]{4}/[0-9]{2}/(.+)$ /$1 [NC,R=301,L]
    
    # the rest of the rules
    RewriteRule ^atom.xml$ feed/ [NC,R=301,L]
    RewriteRule ^rss.xml$ feed/ [NC,R=301,L]
    RewriteRule ^rss2.xml$ feed/ [NC,R=301,L]
    RewriteCond %{HTTP_USER_AGENT} !FeedBurner  [NC]
    RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
    RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/handle [R=302,NC,L]
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    Also, if this is in an .htaccess file, you need to remove the leading slash in the rule match so that it looks like this: ^[0-9]{4}/[0-9]{2}/(.+)$