.htaccess IP problem

Internet54

Verified User
Joined
Dec 1, 2007
Messages
29
My site is not accessible via IP because I have a mod_rewrite to make the site use the www. precursor.

Below is the contents of my .htaccess file

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

How can that be rewritten to not add the www. to an IP address?
If that doesn't make any sense here you go.

mydomain.com --> www.mydomain.com
123.456.789.0 --> www.123.456.789.0 (this will not open the site)

Thanks,
David
 
Then do it simple:

replace:
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

with this:

Code:
RewriteEngine on
# ipaddress check
RewriteCond %{HTTP_HOST} ^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$) [NC]
RewriteRule ^ http://www.yourdomain.com%{REQUEST_URI} [L,R=301]

# fqdn check
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
Back
Top