Forum Moderators: phranque

Message Too Old, No Replies

Force Non-WWW Subdomains

         

ambaxter

6:40 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



I thought this would be a pretty simple answer to find, but so far none of the solutions I've found have worked.

The search engines have indexed WWW versions of my subdomains. How do I use htaccess to force non-WWW subdomains.

jdMorgan

10:02 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Confusing... "www" *is* a subdomain. www.xyz.example.com and xyz.www.example.com are both sub-subdomains.

Please provide clear examples of the problem URLs (using example.com, as above), your desired URLs, the code that you have tried so far, a description of your testing, and the results.

Thanks,
Jim

ambaxter

10:12 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



as in, there are versions such as www.subdomain.example.com being indexed (believe it or not).

I want to take off the www and redirect the visitor to subdomain.example.com.

[edited by: jdMorgan at 11:17 pm (utc) on June 18, 2009]
[edit reason] example.com [/edit]

jdMorgan

10:40 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And what have you tried so far?
(If this question is unclear, please see our Forum Charter [webmasterworld.com])

Before even starting a coded solution, be sure that there are no links anywhere on your site to "www.subdomain.example.com" and if you use Google Webmaster tools, remove any "www/non-www" preference you have set on the GWT Site Configuration->Settings page.

Jim

ambaxter

10:47 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



So far, we've tried the following -- without success. Also, we have ensured that all of the other things you mention are in place.

Options +FollowSymlinks
RewriteEngine On

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

[edited by: jdMorgan at 10:54 pm (utc) on June 18, 2009]
[edit reason] example.com [/edit]

jdMorgan

10:52 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where is this code located? -- in /.htaccess, or in a server config file such as httpd.conf?
If in a server config file, is it inside a <Directory> container, and if so what directory path is specified?

Do URLs such as www.subdomain.example.com successfully resolve to your server and serve content?

Jim

[edited by: jdMorgan at 10:53 pm (utc) on June 18, 2009]

ambaxter

10:58 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



this is in the htaccess file. When WWW is added to the subdomains, it works properly.

The problem is that since Google somehow got a hold of these versions, there is a serious duplicate content issue and we're seeing the effects of it.

jdMorgan

11:15 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code you posted should have worked -- at least for "subdomain" specifically, and also assuming that you completely flushed your browser cache before testing and that you placed this redirect ahead of any others in the file. However, if you need to solve the general case, I'd suggest:

Options +FollowSymlinks
RewriteEngine on
#
# Externally redirect to remove "www" prefix from subdomains
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com [NC]
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]
#
# Externally redirect to canonical www subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Replace the broken pipe "¦" character with a solid pipe before use; Posting on this forum modifies the pipe characters.

Jim