.htaccess 从 IP 地址重定向到实际域 [英] .htaccess redirect from IP adress to actual domain
问题描述
如何将 IP 重定向到实际域?例如:
How do I redirect IP to actual domain? For example:
123.45.678.901 到 www.example.com
123.45.678.901 to www.example.com
以及所有子文件夹和子页面,如
and all subfolders and subpages like
123.45.678.901/all-pages 到 www.example.com/all-pages
123.45.678.901/all-pages to www.example.com/all-pages
此外,我的 SearchConsole 也识别相同 IP 的顶级链接站点",但方式如下:
Also, my SearchConsole also recognizes "top linking sites" for the same IP but in this manner:
IP 123.45.678 ---------------------------- 38,132 个链接
IP 123.45.678 ---------------------------- 38,132 LINKS
IP 123.45.678.901 ------------------------- 3,617 个链接
IP 123.45.678.901 ------------------------- 3,617 LINKS
所以我可能也应该重定向 123.45.678.这可能吗?如何实现?
So I probably should redirect 123.45.678 as well. Is that possible and how?
还有一件事 - IP 在 HTTP 中打开,域在 HTTPS 协议中打开.
One more thing - IP opens in HTTP and domain opens in HTTPS protocol.
推荐答案
这里是此类问题的解决方案
Here is the solution to this kind of problem
在 .htaccess 文件中输入下一个代码:
In the .htaccess file put next code:
RewriteBase /
RewriteCond %{HTTP_HOST} ^123\.45\.678\.901$
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
所以如果你有一个像 IP 这样的 URL
So if you have a URL wit IP like
123.45.678.901/all/other/pages/
执行此代码后,所有页面都将被重定向到
after implementing this code all pages are going to be redirected to
www.example.com/all/other/pages/
我希望我可以帮助任何人,因为这是可能破坏您的 SEO 的非常重要的因素之一.
I hope i could help anyone because this is one of very important factors which may ruin your SEO.
这篇关于.htaccess 从 IP 地址重定向到实际域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!