.htaccess re-directing to folder within my website?

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 (“autos”) in my htaccess re-direct?

Thanks

Here are some examples you can look at:

http://httpd.apache.org/docs/2.2/rewrite/remapping.html#canonicalurl

http://httpd.apache.org/docs/2.2/rewrite/remapping.html#canonicalhost

Thanks Jeff!

That is not entirely correct as those examples just use [R], which google sees as a temporary redirect (if not supplied, the status for the [R] flag defaults to 302). If the URL changes indefinitely one should use [R=301], for HTTP status [URL=“http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2”]301.

Hi,

Thanks for the reply. This is the syntax I came up with. What do you think? Thanks

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

Looks good! I would make one small amendment; use %{REQUEST_URI} instead of (.*) and $1 :


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

Simply to avoid a regex that’s not really needed :slight_smile:

I’m dubious about this one. Normally, each rewrite rule matches against the output of the previous rewrite rule. If there were no previous rewrite rules, then FONT=Courier New/$1[/FONT] and .?/%{REQUEST_URI} are functionally equivalent. But if there were previous rewrite rules, then the .?/%{REQUEST_URI} construct would throw away that output.

Presumably, the motivation for .?/%{REQUEST_URI} is that it’s supposed to be faster… Time to break out the measurement tools. The difference between the two is 2 nanoseconds. That’s about as micro as a micro-optimization will ever get. And to boot, it was the (.*) version that was 2 nanoseconds faster.

I see only downsides and no upside.

I stand corrected!