将 IP 重定向到域 [英] Redirect IP to domain

查看:28
本文介绍了将 IP 重定向到域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 搜索结果将我的网页显示为 (ip)/mypage.html 而不是 https://www.mydomain.com/mypage.html.我相信解决方案是将 ip 重定向到域.我找到了很多非常相似的方法来做到这一点,但没有一个对我有用.我有一个将 http 重定向到 https 的现有规则.这是我的 .htaccess 文件目前的样子:

Google search results are showing my pages as (ip)/mypage.html instead of https://www.mydomain.com/mypage.html. I believe the solution is to redirect the ip's to the domain. I've found many, very similar ways to do this, but none of them are working for me. I have an existing rule that redirects http to https. This is what my .htaccess file currently looks like:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^11.11.11.111$ [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^([a-z.]+)?mydomain.com$ [NC]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]

我做错了什么?

推荐答案

您的 2 个重写条件发生冲突.它们要求 http_host 同时为 11.11.11.111 和 *.mydomain.com.只需添加一个或类似的:

Your 2 rewrite conditions clash. They require http_host to be 11.11.11.111 and to be *.mydomain.com, at the same time. Just add an or like so:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^11.11.11.111$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?mydomain.com$ [NC]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]

这篇关于将 IP 重定向到域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆