Something like this might work:
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([^0-9]{2})(.+)$ http://www.mydomain.com/$3$4
The caret ‘^’ inside square brackets means do not match the listed characters. It works for your example but it may not work for all situations. To capture all situations, you may need to use a rewrite rule block listing multiple conditions.
Yes that works! Thank you so much for your help!
I actually noticed a few other problems that still exist pertaining to the archives again. Here is what’s going on:
On a single day or a single month page, clicking the next page feature to get to page 2 breaks. Examples:
Page 2 on monthly archives: (ie: Jun >> June page 2)
http://www.mysite.com/2013/07/page/2/ redirects>>>>>>>>> http://www.mysite.com/page/2/
Page 2 on a single day of archives:
http://www.mysite.com/2013/08/21/page/2/ redirects>>>>>>> http://www.mysite.com/21/page/2/ 404 not found
Is this something you can help me with? Let me know if you need to to outline the problem better. Thanks.
I was afraid it would not be that easy. I think you are better off using the mod_rewrite module instead of trying to create the ideal regexp for a redirect. With mod_rewrite you can stack multiple conditions linked by logical AND & OR to determine if a particular rewrite rule should be applied. You can see an example of this because WP uses one to enable permalinks. It’s the portion after # BEGIN WordPress in your installation’s .htaccess file.
Unfortunately, I can’t offer any code to get you going, one silly error and your entire site returns 500 errors. I don’t want to be responsible for that. There’s lots of examples on the ‘net and there’s the official documentation. I suggest you start with a single basic condition and rule. Incrementally build on that. You will have a better idea where things aren’t right this way. The error logs often give a good clue as well.
Sorry I can’t be of more help. If you get stuck on something, I may be able to shed some light, but I’m uncomfortable producing the entire block of code. I hope you understand. Good luck.
Thanks so much for the response. Doing some more searching on it I was able to find someone with a very similar problem here: http://wpquestions.com/question/showChrono/id/8468
The recommended fix was to add:
RewriteCond %{REQUEST_URI} !page
RewriteRule ^[0-9]{4}\/+[0-9]{2}\/+(.+)$ /blog/$1 [L,R=301]
So i took that and basically replaced it with the previous code I was using. (ended up being different slightly than yours fyi, but yours works the same way interchangeably):
Original code:
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/([a-z0-9\-/]{4,}) http://www.sweetfreestuff.com/$1
New code (seems to fix archives problem):
RewriteCond %{REQUEST_URI} !page
RewriteRule ^[0-9]{4}\/+[0-9]{2}\/([a-z0-9\-/]{4,}) http://www.MYSITE.com/$1 [L,R=301]
Now my question for you, sir, is how does the code look and how does it look compared to the example fix from that page? Did I transpose everything correcty? Am I missing any characters or commands? Although it seems everything is working fine now, Just would like to doublecheck with someone who actually know what they are doing to see if you think this code holds water.
Thanks you very, very much for your help again.
btw, I have no idea what (.+)$ means
I can’t comment on the regexp itself as I’m unsure of all the possible URL variants it needs to match or not match, but it does appear to be a valid regexp. Your site would probably be broken if it were not.
As for the rewrite rule in general, perhaps you just didn’t include it here, but you should include the entire context, similar to what WP does for the permalinks. Based on what you posted, the entire block might look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !page
RewriteRule ^[0-9]{4}\/+[0-9]{2}\/([a-z0-9\-/]{4,}) http://www.MYSITE.com/$1 [L,R=301]
</IfModule>
The RewriteBase may need to be altered if your WP installation is not in the root of your site. The nice thing about this approach is it’s easy to add more conditions if you discover more anomalies.
As for what (.+)$ means, it matches anything 1 or more characters in length that occur at the end of the URL not matched by prior regexp. Whatever is matched is assigned to a $# back reference.
`
That was just what I was looking for was someone to confirm the validity of the regexp. Good to know thanks!
Also, yes, I just didn’t include the whole code snippet. I did place it in between the <ifModule> tags after RewriteBase /.
Thanks for the additional information and for answering my question as (.+)$ means. Although not sure I fully understand. I know when I was testing if I added that to the end of the current line I’m using, it would seemingly work in the same way.
Thanks again for your help and quick responses, you have been extremely helpful!
I’m pleased to be of service and that you arrived at a workable solution.