Forum Moderators: phranque

Message Too Old, No Replies

Google Indexed IP and Name Server + Site

Mod Rewrite Help

         

Naveenn

9:57 am on Apr 14, 2011 (gmt 0)

10+ Year Member



Hi,

Google has indexed more than 3 copies of my site and this seems to have brought my traffic down.

Google has indexed entire content with copies
1) www.domain.com
2) ns1.domain.com
3) Ip.xx.xx.xx of the site
4) ns1.other-suspended-domain.com

After reading the forums, I got to know that one must use 301 redirects via htaccess. Thanx to Jd Morgan, I was able to redirect some of the copies with the following code.


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^[0-9]+(\.[0-9]+){3} [OR]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]


The above code helped to redirect all IP.xx.xx.xx requests to www.domain.com but it is unable to redirect [ns1.domain.com...] to www.domain.com

I tried changing "{HTTP_HOST} ^example" to "{HTTP_HOST} !^example" but that seems to send the server in redirect loop.

Please help to get this working.

Thanx.

jdMorgan

3:27 pm on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's likely that *no* code on this server can redirect requests for "ns1.example.com" because those requests won't resolve to this server, and therefore cannot invoke the redirect code.

The code to redirect "ns1.example.com" requests would need to be installed on the "ns1.example.com" server -- to be invoked only in the case of HTTP (and not DNS) requests to that server.

Adding a "!" to a line of code is a rather momentous change, since "!" at the beginning of a regex pattern means "NOT." Please don't modify any .htaccess code unless you fully understand the modification, meaning what the changed code does to your server behavior, and what that change in behavior will mean to human visitors and to search engines... To do so often results in "SEO suicide." There's no safe substitute for studying and understanding every detail of every directive you add to .htaccess. The resources cited in our Apache Forum Charter may be of some use in this regard.

Jim

Naveenn

4:53 pm on Apr 14, 2011 (gmt 0)

10+ Year Member



Got it working .. with both the code you had suggested in the post I had read. Lemme know if this will cause an issue with the server. As of now .... evething seems to work nicely and as I wanted.


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^[0-9]+(\.[0-9]+){3} [OR]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteEngine on
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Naveenn

5:06 pm on Apr 14, 2011 (gmt 0)

10+ Year Member



Ok, now I understand that only the second part is good enough to get everything done.

RewriteEngine on
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

g1smd

8:50 pm on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are several valid requests that your code will not redirect:

www.example.com./<anything-or-nothing>
with trailing period on hostname,
www.example.com:80/<anything-or-nothing>
with port number on hostname,

as those DO begin
www.example.com
and your code redirects only requests that do NOT begin with that.

Small modification to fix this:

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


The
( )?
replaces the extra RewriteCond in your code.
The
$
forces the redirect for any requested hostname that is not "exactly" www.example.com

Naveenn

6:38 am on Apr 15, 2011 (gmt 0)

10+ Year Member



The code in use is redirecting your examples just fine.

www.example.com./
or
www.example.com:80/