Forum Moderators: phranque
RewriteCond %{HTTP_HOST} .
# If requested domain is the IP address
RewriteCond %{HTTP_HOST}!123\.34\.678\.910
# redirect to requested page in canonical domain
RewriteRule (.*) http://example.com/$1 [R=301,L]
Here's what I currently have in place:
RewriteCond %{HTTP_HOST} .
# And if requested domain is NOT the canonical domain
RewriteCond %{HTTP_HOST}!^example\.com
# redirect to requested page in canonical domain
RewriteRule (.*) http://example.com/$1 [R=301,L]
I also see that vps.example.com is also not redirecting to the canonical domain...Am I missing something? Thanks
The new code you posted has a logic error in it, and won't work; In mod_rewrite "!" means NOT.
I don't know what the special significance of "vps.example.com" might be. However, one thing to bear in mind is that only requests which access the directory in which your .htaccess file(s) resides (or subdirectories of that directory) can be affected by the code in your .htaccess file(s). So if a request by IP address or a request to "vps" does not load the same home page and/or robots.txt file as a request to the canonical domain, then your redirect cannot work.
Jim
# redirect to requested page in canonical domain
RewriteRule ^/(.*)$ http://example.com/$1 [R=301,L]
Jim
#1 Server Response: [123.45.67.890...]
HTTP Status Code: HTTP/1.1 302 Found
Date: Thu, 01 Feb 2007 19:21:38 GMT
Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a
Location: http://example.com
Connection: close
Content-Type: text/html; charset=iso-8859-1
Redirect Target: http://example.com
#2 Server Response: http://example.com
HTTP Status Code: HTTP/1.1 200 OK
Date: Thu, 01 Feb 2007 19:21:38 GMT
Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.4.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a
X-Powered-By: PHP/4.4.4
Connection: close
Content-Type: text/html; charset=UTF-8
The same is true for the subdomain. Shouldn't these be returning a 301, not 302? thanks!