In most cases, WordPress actually is smart enough to do that on it’s own. But if you’re concerned, tou’d be best served by doing it via .htaccess.
RewriteRule ^([0-9]{2})/(.*)$ http://domain.com/$2 [L,R=301]
That looks for anything that starts ##/POSTNAME and turns it into POSTNAME 🙂 Put it above the START WORDPRESS line.
Done and done.
Thread Starter
eoren1
(@eoren1)
Thanks Ipstenu. Appreciate the help!
My issue isn’t so much WP internally, it’s every FB page post and every incoming link I’ve managed to build up over the past 18 months. Plus a few internal links from one post to another.
This is the rewrite rule I got from a site meant to generate such a redirect:
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://wednesdaysinmhd.com/$4
However, that was to essentially change over from Day and Name to just Postname.
Ideally I would like to change to:
domain.com/town/category/postname
Would rules in the htaccess also serve to redirect links to specific posts with the Day and Name permalink structure to the new location?
Thanks again!
E
Thread Starter
eoren1
(@eoren1)
The town part is a fixed term by the way. I just realized that I chose a domain without a keyword I needed and was going to fix that by inserting the town name in the url as part of the permalink structure.
Ah so your URLs were YYYY/MM/DD then 🙂 (you said “I currently have my permalinks set up as day and name.” so I assumed it was just DD/NAME)
But yeah, that’s what I do too.
And if you want category/postname, just change the permalink to that, BUT keep the .htaccess redirect the way you did. WordPress will take domain.com/postname and on its own redirect you to the right place 🙂 How cool is that?
Thread Starter
eoren1
(@eoren1)
Hi
So I added the rewrite rule and updated the permalink structure
However, when following a link on my Facebook page (which has the yyyy/mm/dd/name structure) or Google links to specific posts, I get a 404 error.
Any suggestions?
Thanks!
E
Thread Starter
eoren1
(@eoren1)
Also, internal links – such as when I manually inserted a link to another blog post in the text were also broken and led to a 404 page.
I reverted back to the year/month/day permalink for now.
Really hoping I can fix this though.
Try this one:
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://wednesdaysinmhd.com/$4 [L,R=301]
Sometimes that works better than a Match.
Thread Starter
eoren1
(@eoren1)
Almost.
It is now sending me to domain.com/postname
I need it to send me to domain.com/town/category/postname
I have tried custom permalink as /%category%/%postname% with a optional category of Town
And I’ve tried custom permalink as /town/%category%/%postname%
If I type into the url bar after getting a 404 and manually add in the /town/category it works! Do I need to add those to the end of the rule?
Thread Starter
eoren1
(@eoren1)
Not sure if it matters but I do use W3 Total Cache and CloudFlare
I have emptied all caches after each step above
Turn of w3tc while you’re playing with this 🙂
Try RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://wednesdaysinmhd.com/town/$4 [L,R=301]
Set your permalink to /town/%category%/%postname%
WordPress SHOULD go from domain.com/town/postname to domain.com/town/category/postname
Though there’s NO way to dynamically generate the category in the htaccess.
Thread Starter
eoren1
(@eoren1)
Thanks for your help and patience with all of this!
Turned off W3TC
Used the new rule and permalink
If I put in the category in permalink, external links broke. If I inserted the correct category into the url, it worked.
Changed it to /town/%postname%/ which seemed fine until I followed a Google Tag link which broke because its url was domain.com/tag/— and was missing /town/ before the /tag/
I’m not sure why WP isn’t correctly sending me to the address based on the permalink rules
I have reverted back to Day and Name permalink structure for now (ie YYYY/MM/DD). By the way, I’m only doing this with the expectation that it will make a big difference in my SEO. If the url words are not strong elements in SEO, I’m happy to drop this.
Thanks again,
E
until I followed a Google Tag link which broke because its url was domain.com/tag/— and was missing /town/ before the /tag/
Hrm. Yeah, adding in /town/ is going to make it trickier. If you JUST went to domain.com/permalink, you’d be better off.
Thread Starter
eoren1
(@eoren1)
Thanks Ipstenu.
Not sure what domain/postname has to offer in comparison to domain/year/month/day/postname
Ideally (and only for SEO purposes), I would like to have domain/town/category/postname. Potentially I could use town under the optional category base in the permalink settings though that doesn’t seem to work regularly when i try it out.
Not sure why WP isn’t taking the domain/postname and following the set permalink rule to send that to domain/category base/category/postname
I should explain this better.
WP can take domain.com/postname/ and go to domain.com/categoryname/postname
It can take domain.com/postname/ and go to domain.com/YYYY/postname/
It CANNOT go to domain.com/BASE/anything/postname/
That said? The SEO difference between domain.com/town/catname/postname and domain.com/postname are … zilch. Zero. Zip. Nada.
The HEO (human experience opt.) is minimal but a valid point.
domain.com/postname is shorter and, thus, more likely to be remembered.
Thread Starter
eoren1
(@eoren1)
Thanks. Without any SEO difference there really is no reason for me to keep pounding away at this. I’ll just rest with my less than perfect choice of permalinks when I set up the site in August 2010 and let it go at that.
I really do appreciate all of your help.
Sincerely
Eyal