Need help with .htaccess redirects

cmeinck

Well-known member
Years ago, I migrated from Joomla to Wordpress. Instead of well executed .htaccess directives, I loaded up on individual 301 redirects. There are two redirects that if done correctly would allow me to remove a ton of individual redirects. I believe that the large .htaccess file is responsible for slow initial load times.. For example:
Code:
Redirect 301 /articles/2009/5/22/article-title/ http://www.mysite.com/article-title/2009/05/22/

Redirect 301 /2009/5/20/different-article-title/ http://www.mysite.com/different-article-title/2009/05/20/

If anyone can help, I'd greatly appreciate it.
 
I am trying to come up with a pattern based on limited examples. Try this:

Code:
RewriteEngine On

RewriteRule ^articles/([0-9]+)/([0-9]+)/([0-9]+)/([^/]+)/$ /$4/$1/$2/$3/ [R=301,L]
RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/([^/]+)/$ /$4/$1/$2/$3/ [R=301,L]

This would go in a .htaccess file in your web root.
 
Sorry for the late response. I've been meaning to circle back and thank you. This worked perfectly and I greatly appreciate it. Still suffering from domain changes and software migrations, mostly my Joomla to Wordpress move of a few years back.
 
@Jake Bunce I was hoping you could help with a different .htaccess question. I currently have two .htaccess directives. One adds a trailing slash to posts, assuming there isn't one. Search engines are redirected to the one with the trailing slash.

My Wordpress posts used to have the date appended. So a post would end with this-is-my-post-2014-07-07. I have a directive to redirect to this-is-my-post.

How would I append the second directive so that it's a single hop and includes the trailing slash. GWT shows an abundance of duplicate meta descriptions. I'm thinking it might be a good idea to reduce the hops from 3 to 2.

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]

RewriteEngine On
RedirectMatch 301 ^/([^/]+)/([0-9]{4})/([0-9]{2})/([0-9]{2})/$ http://www.mysite.com/$1

Thanks!
 
Back
Top Bottom