Eyad Farra
Eyad Farra

Reputation: 4423

How to redirect users if they enter domain IP instead of domain name

My site for example named example.com and IP Address for it is 12.12.12.12 .

All whats I need is when some one enter IP Address instead of the domain name the server must redirects the user to site with its name not IP address.

In other word, when some one enter 12.12.12.12 the server must open site with its domain name example.com.

How can I do that?

Upvotes: 0

Views: 411

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

It is pretty simple.
Put this code in your htaccess

RewriteEngine on

RewriteCond %{HTTP_HOST} ^12\.12\.12\.12$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Upvotes: 1

Related Questions