The following mod_rewrite rule accomplishes the task of rewriting www.domain.com/2011/11/page
to www.domain.com/page
but breaks www.domain.com/2011/11/
(i.e. breaks WordPress Archive listings) and redirects it to the root of the site.
The rewrite rule should only rewrite items that have content after ^([0-9]{4})/([0-9]{1,2})/page
but not ^([0-9]{4})/([0-9]{1,2})/
.
RewriteRule ^([0-9]{4})/([0-9]{1,2})/(.*)$ /$3 [NC,R=301,L]
Any recommendations?
ANSWER
The initial forward slash was missing at the beginning:
RewriteRule ^/([0-9]{4})/([0-9]{2})/(.*)$ /$3 [NC,R=301,L]
and the WordPress permalink entry needed:
/%postname%/
instead of:
%postname%
although I am not sure how much the latter helped.
I think you need to change the * to a +
should be
With (.), it could possibly match nothing, thus a request like “/2011/11/” will match but the back reference for (.) will be blank, thus the rewrite goes to “/”. The + indicates that there needs to be at least 1 character satisfying the “.” in the regular expression.