重定向I​​P域重定向

由网友(唔着胃说心疼。)分享简介:谷歌搜索结果显示我的页面作为(IP)/mypage.html代替的https:// WWW .mydomain.com /的mypage.html 。我认为,解决的办法是重定向IP的域。我发现很多非常相似的方式来做到这一点,但他们都不是为我工作。我有一个重定向HTTP到HTTPS现有规则。这是我的.htaccess文件...

谷歌搜索结果显示我的页面作为(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]

我是什么做错了吗?

What am I doing wrong?

推荐答案

您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]
阅读全文

相关推荐

最新文章