0

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

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

1 Answer 1

1

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") {
    http_response_code(301);
    header("Location: https://localhost/" . $_SERVER['REQUEST_URI'];
    exit();
}

or with Apache HTTP mod_rewrite:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule ^.*$ https://localhost%{REQUEST_URI} [R=301,L]
1
  • 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. Jul 5, 2020 at 10:03

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