Help with Wordpress Permalink/htaccess 301 redirect issue

brometheus55

Banned
Jan 11, 2012
84
1
0
need some help yall.

I am currently attempting to change the permastructure of all of my wordpress posts from /%year%/%monthnum%/%postname%/ to just /%postname%/.


I have already made the change in wordpress and added the following code to my htaccess file to initiate the 301 redirects:


RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.+)$ http://www.mydomain.com/$3


Now everything is working perfectly except for 1 thing. It has caused all archived date pages, for example www.mydomain.com/2013/8/20, to redirect to www.mydomain.com/20 which causes 404s.


My question is how do i edit the code to not reflect those archived dates. I imagine it's something fairly simple but i know minimal coding and have already spent hours searching online only to come up short, and i am very surprised as the code I used was given as a common fix. I assume most people didnt either use their calendar widgets, or never noticed this problem. Also, all the 301/permalink plugins for wordpress are shit/dont accomplish this to my knowledge. I found one that would have worked except it was registering 302s ftl.



anyway please and thanks for help.





i6FDaKD.gif


nXX6KrR.gif
6THW0yV.gif


6THW0yV.gif
 
  • Like
Reactions: seofactory


Try this regex in place of yours,

Code:
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([a-z0-9\-/]+) http://yoursite.com/$1

The above regex will not match with the individual archives (Year wise, Monthwise etc.) and so those pages shouldn't have any issues.
 
Did you mean to add that line in addition to what I had or in place of it? Either way, I tried both and with just the one you gave me, the posts don't redirect from their original permastructure. Thanks for the suggestion.
 
Those asses are distracting. Completely misread your post and perceived that you were unable to display your archived pages without even looking at the code.

Talked to the OP and got a better understanding of his issue.

A simple solution to the above issue is

Code:
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/([a-z0-9\-/]{4,}) http://www.site.com/$1

We change the value of every url element happening after %month% to be set at a minimum character of 4 to circumvent the issue. So everything after the %month% which has a character count of 1, 2 or 3 remains the same. While everything which is more than 3 characters gets redirected from http://site.com/%year%/%month%/%post-slug% to http://site.com/%post-slug%

There are other work arounds for this such as using lookahead assertions with a negative value. But this is the easiest solution to circumvent the issue that the OP was facing.
 
Those asses are distracting. Completely misread your post and perceived that you were unable to display your archived pages without even looking at the code.

Talked to the OP and got a better understanding of his issue.

A simple solution to the above issue is

Code:
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/([a-z0-9\-/]{4,}) http://www.site.com/$1
We change the value of every url element happening after %month% to be set at a minimum character of 4 to circumvent the issue. So everything after the %month% which has a character count of 1, 2 or 3 remains the same. While everything which is more than 3 characters gets redirected from http://site.com/%year%/%month%/%post-slug% to http://site.com/%post-slug%

There are other work arounds for this such as using lookahead assertions with a negative value. But this is the easiest solution to circumvent the issue that the OP was facing.



You are a freaking life saver man! This thread is guaranteed to help some others in the future. Bloghue is the man!


we_re_not_worthy-8bab6c65f4c32c98973856396c9c93cc.jpg