Page 1 of 1

IP to url htaccess rule?

Posted: Tue Jun 28, 2011 7:53 am
by eshban
Hello,

My website is also accessed by my website ip address. I want that if any user trying to open my website by my website ip address, it will be automatically redirected to my website url.


Can anyone guide me about this.

Regards,
eshban

Re: IP to url htaccess rule?

Posted: Tue Jun 28, 2011 9:35 am
by John Cartwright
Use a RewriteCond + REMOTE_HOST variable to apply redirection rules to a specify rule, i.e.,

Code: Select all

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
//your redirection rule here

Re: IP to url htaccess rule?

Posted: Tue Jun 28, 2011 11:01 am
by twinedev
Here is what I use. It says that if someone comes to the site not using www.example.com, redirect them to www.example.com, including the rest of the URL.

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