0

I'm kind of new to writing htaccess rules. I want to make the urls in my website as simple as possible.

Let's say I want to "map" /home/ directory for root domain. So, http://www.domain.com would display content from /home/ directory without changing url.

Moreover, I don't want users / google to access to: http://www.domain.com/home/, so, if somebody goes to that URL, I want to redirect them back to my root domain: http://www.domain.com.

I'm seeing that google is indexing both directories with the same duplicate content. http://www.domain.com http://www.domain.com/home/

Is there anything I can do to stop this? I don't want to use robots.txt because i've heard it's a bad practice.

RewriteEngine on
RewriteBase /

# Redirect /home/ dir to 'www.domain.com'
#RewriteCond %{REQUEST_URI} ^/home/$ [NC]
#RewriteRule ^(.*)$ / [R=301,L]

# Show /home/ dir for 'www.domain.com'
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /home/$1 [L]

If I enable all the lines from this code, I get a redirect loop that never ends.

Also, I'm facing the same problem when trying to add "seo friendly" urls. I'm trying to map "http://www.domain.com/thread/thread-name/" to "http://forum.domain.com/thread-name/", and although it works fine, I'm still having 2 duplicate URLS showing the same content.

I would like to heard the best practice to avoid search engines from indexing duplicate content. Should I redirect it to 404? I don't want to use robots.txt to implement this because there're lots of files / directories combination, and it won't work for my purpose.

Thanks a lot!

Ramiro
  • 47
  • 1
  • 7

1 Answers1

2

Instead of this:

# Redirect /home/ dir to 'www.domain.com'
#RewriteCond %{REQUEST_URI} ^/home/$ [NC]
#RewriteRule ^(.*)$ / [R=301,L]

try:

# Redirect /home/ dir to 'www.domain.com'
RewriteCond %{THE_REQUEST} \ /+home/([^\?\ ]*)
RewriteRule ^ /%1 [R=301,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Thanks a lot for such a great solution! It works great. I'm wondering what should I do now to remove "/home/" url from google index, so that I don't have duplicate content. I'll keep searching, thanks! – Ramiro Oct 08 '14 at 15:40