Rewrite Url From Ip To Domain

I had a website running at IP (lets say) 11.11.11.11.

My .htaccess is


RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php

I recently purchased a domain (lets say) mydomain.com and configured it. Website loaded with both IP and domain successfully.

Now, I want to rewrite in a way that all accesses via "IP" are redirected to domain, i.e. 11.11.11.11/contact/sample to be redirected as mydomain.com/contact/sample.

And of course, all other links.

Any help?

try this:


RewriteEngine on

RewriteCond %{REMOTE_HOST} !^11\.11\.11\.11

RewriteCond %{REQUEST_URI} !/contact/sample$

RewriteRule ^(.*)$ mydomain.com/contact/sample

/contact/sample was just an example, :)

its not possible to add all the links in htaccess for me.