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

General Discussion

Shane McC
Shane McC
3,005 Points

.htaccess Question for re-directing URLS?

How would I tell the search engines that I'm re-directing my URLS to http://mydomain.com/autos/1998/Toyota/Camry from http://www.mydomain.com/1998/Toyota/Camry

I'm adding in the "autos" in between every vehicle I have on my website.

How would I account for that in my htaccess re-direct?


1 Answer

Alan Johnson
Alan Johnson
7,625 Points

This should do it for you:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

In general you'd use mod_rewrite to pull that off, but I found exactly what you were looking for over on Stack Overflow.

One thing to note is that you'll need Apache to be configured to allow you to use a .htaccess file and for it to allow you to use mod_rewrite in the .htaccess file. It's not always available, but usually on shared hosting it is.

Shane McC
Shane McC
3,005 Points

Thanks Alan, when I launch my website I'll be giving this syntax a try. Appreciate the help.