IP Redirect Question

I have many different page results showing up in Google for a variety of pages which are showing content featuring IP number instead of the domain. I want to change this so that users clicking on these are redirected to the spelled domain version and that ultimately, Google will not show these in their index.

My thought is that I need to do some kind of global redirect which would match IP page to domain page. I would also need to account for an IP range (XX.XX.0.0 - XX.XX.255.255 ), but I’m not sure how to do all of this?

“Wherever the host is not www.example.com, redirect to www.example.com with the same URI”

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

Source: http://articles.sitepoint.com/article/apache-mod_rewrite-examples

For testing server purposes, how would I exclude specific addresses from this rule so that I can avoid it redirecting locally?


By using more RewriteCond statements to define your exclusions (an Apache question).