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
IP to url htaccess rule?
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: IP to url htaccess rule?
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 hereRe: IP to url htaccess rule?
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]
[text]RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.net [NC]
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L][/text]