Forum Moderators: phranque

Message Too Old, No Replies

Redirect or Rewrite ?

strip subdomain for pages to point to main domain

         

JamesT

1:24 pm on Feb 15, 2009 (gmt 0)

10+ Year Member



Hi All,

My first post here, I have searched fairly extensive and couldnt find an example that works for my situation. I am using wordpress multi user with permalinks.

I have a permanent redirect as below and it works great

RewriteEngine on
RewriteCond %{HTTP_HOST} mydomain.myhost.com [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

It redirects exactly as I want it to, however if I type in a url

mydomain.myhost.com/2009/mypost

it doesnt redirect the url to

mydomain.com/2009/mypost

basically I want to strip the myhost bit, to avoid any duplicate content on google. I have tested that both conditions work if I type below into a browser.

mydomain.myhost.com/2009/mypost
mydomain.com/2009/mypost

I hope there is a simple rewrite that I can add to my .htaccess given in the above working sample.

thanks in advance for any help..

[edited by: jdMorgan at 4:30 pm (utc) on Feb. 15, 2009]

jdMorgan

4:29 pm on Feb 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteEngine on
#
# Redirect all non-canonical domain variants to canonical hostname
RewriteCond %{HTTP_HOST} !^mydomain\.com$
RewriteRule (.*) http://mydomain.com/$1 [R=301,L]

If the requested hostname is NOT exactly "mydomain.com", then redirect to "mydomain.com"

Jim