I am facing this problem for quite a long time. When I enter the IP address of my website it take me to the website but the IP address doesn't change to the Domain Name. I am hosting my website on a Virtual Machine on Google Cloud. I am using the Google Cloud service as a hosting service for my website. Can someone help me in solving this problem? This is how my htaccess file now looks like:

BEGIN WordPress

The directives (lines) between BEGIN WordPress and END WordPress are

dynamically generated, and should only be modified via WordPress filters.

Any changes to the directives between these markers will be overwritten.

RewriteEngine On RewriteCond %{HTTP_HOST} ^IP\.IP\.IP\.IP [nc,or] RewriteCond %{HTTP_HOST} ^example\.org [nc] RewriteRule (.*) http://example.org$1 [R=301,L] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]

END WordPress

  • 1
    What web server do you have installed and running? What configuration are you using for its virtual hosts? – Stephen Ostermiller Jul 4 '20 at 17:55
  • 1
    Please edit the question to provide the requested details so that this could be reopened. – Stephen Ostermiller Jul 4 '20 at 17:55

Since multiple hostnames can resolve to the same IP address, this is something that has to be handled at the HTTP level.

You should issue a 301 Moved Permanently status and a Location header with the same path but replacing the IP address with the desired hostname.

You might be able to configure your HTTP server to do that. You might have to do it with explicit server-side programming.

e.g. in PHP:

if ($_SERVER['HTTP_HOST'] != "localhost") {
    header("Location: https://localhost/" . $_SERVER['REQUEST_URI'];

or with Apache HTTP mod_rewrite:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule ^.*$ https://localhost%{REQUEST_URI} [R=301,L]
  • I think I have already made these changes to my htaccess file. Can you please see it in the question and tell me if its right because it's not working. – Mubashir Ahmed Jul 5 '20 at 10:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.