Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Joel Rivera
Joel Rivera
29,401 Points

How to handle .htaccess 301 redirect

I'm converting a website from a Closed Source CMS to WordPress. The old CMS has some ugly url's that have decent page rank. I want to clean them up.

They look like http://www.example.com/community/area/All%20of%20Mount%20Vernon/

And I want it to look like http://www.example.com/mount-vernon

What is the proper way to do this with htaccess? Also do I just put the 301 redirect in the WordPress htaccess file?

Note I don't have access to the other CMS files because it's closed source so I can't put any code into their system. Not sure if I would need to.

Thanks everyone

2 Answers

Sarah Bradberry
Sarah Bradberry
7,115 Points

I would put it in the root htaccess file because it's easier to keep track of, but more tech savvy folks might have a good reason that another option would be better.

Redirect 301 http://old-url http://new-url

You'll need to use regex to write a string that will redirect the files without the extra stuff. http://regexone.com/ is a good place to learn

Joel Rivera
Joel Rivera
29,401 Points

Thank you Sarah, What do you think about using a free htaccess generator like this one? http://seo-website-designer.com/HtAccess-301-Redirect-Generator or this one http://www.htaccessredirect.net/

Joel Rivera
Joel Rivera
29,401 Points

Also what do you think about the plugin called Redirection? http://wordpress.org/plugins/redirection/

Sarah Bradberry
Sarah Bradberry
7,115 Points

I use the redirection plugin in my wordpress (I recently moved my blog to wordpress from movable type so I had lots of redirects). It's really good but you have to be careful of two things:

make sure you use the htaccess file in the root directory or you'll have to edit your redirects every time you're redirecting a 404.

It's also really easy to accidentally delete all your redirects. You can import them from the htaccess file though (don't ask how I know, lol).

You'll still need to know how to write regex strings if you want to move a lot of content from similar urls

The redirect generator looks really good. I'm only just learning how to write regex strings so that's going to come in handy, thanks! :)

Joel Rivera
Joel Rivera
29,401 Points

The Redirection plugin seems to work well. Do you suggest leaving the trailing / in the redirect?