Jump to content

Rewrite directory to subdomain to avoid duplicate content


Kerosene

Recommended Posts

Both these urls point to the same page:

www.domain.com/subdomain/whatever+search+term
subdomain.com/whatever+search+term

 

Can anyone suggest an elegant way to make it so:

www.domain.com/subdomain/whatever+search+term
301s to:
subdomain.com/whatever+search+term

 

I've cut and pasted a few things together and this works.

But I have no idea about mod_rewrite, and would apprecite if someone could tidy it up a bit.

This is the htaccess in my domain.com/subdomain directory...

Options +FollowSymLinks
RewriteEngine On

#this makes the url prettier - and works fine
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^([^/\.]+)/?$ index.php?s=$1 [QSA,L]

#this is the directory>subdomain stuff i'm not so sure about, it does work though
RewriteRule !\..{3,4}$ - [C]
RewriteCond %{HTTP_HOST} !^subdomain
RewriteCond %{REQUEST_URI} !^.*/$
RewriteRule ^(.+)$ http://subdomain.domain.com/ [R=301,L]

RewriteCond %{HTTP_HOST} !^subdomain
RewriteRule ^(.*)$ http://subdomain.domain.com/$1 [R]

 

Can anyone clean this up a bit? Or at least let me know if it's safe to use (in terms of SEO)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.