我面对这个问题已经很长时间了。当我输入我的网站的IP地址,它会带我到网站,但IP地址不会更改为域名。我是托管我的网站上的一个虚拟机上的谷歌云。我正在使用谷歌云服务作为我的网站托管服务。有人能帮我解决这个问题吗?我的htaccess文件现在是这样的:
BEGIN WordPress和END WordPress之间的指令(行)是进行修改。
RewriteEngine On RewriteCond %{HTTP_HOST} ^IP.IP RewriteCond %{HTTP_HOST} ^example.org RewriteRule (.*) http://example.org$1 RewriteBase / RewriteRule ^index.php$ - RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}!REQUEST_FILENAME./index.php
发布于 2020-07-05 00:32:05
由于多个主机名可以解析到同一个IP地址,所以必须在HTTP级别处理。
您应该使用相同的路径发出301 Moved Permanently状态和Location报头,但将IP地址替换为所需的主机名。
您可能可以配置您的HTTP服务器来执行此操作。您可能需要使用显式服务器端编程来完成此操作。
例如在PHP中:
if ($_SERVER['HTTP_HOST'] != "localhost") {
http_response_code(301);
header("Location: https://localhost/" . $_SERVER['REQUEST_URI'];
exit();
}或者使用Apache mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule ^.*$ https://localhost%{REQUEST_URI} [R=301,L]https://webmasters.stackexchange.com/questions/130391
复制相似问题