简体   繁体   English

在浏览器中访问时,IP地址重定向到URL

[英]IP Address Redirect to URL when visited in browser

When a user visits my sites IP address in a web browser, I'd like to have it redirect to the site's main page (or redirect to a page I choose). 当用户在Web浏览器中访问我的站点IP地址时,我希望它重定向到站点的主页(或重定向到我选择的页面)。 I'm not sure if this is possible but we had basically set up a site on a temp URL (it was http://{IP_ADDRESS}/{SUBDIRECTORY}) and when it was ready we pointed the domain to the folder. 我不确定是否可行,但是我们基本上已经在临时URL(它是http:// {IP_ADDRESS} / {SUBDIRECTORY})上建立了一个站点,当准备就绪时,我们将域指向文件夹。

It works great but it was set in WordPress and some of the links were done using absolute paths so when people click on them, they go to the IP address and thus have a 404 error. 它工作得很好,但是它是在WordPress中设置的,并且某些链接是使用绝对路径完成的,因此当人们单击它们时,他们会转到IP地址,从而出现404错误。 We are obviously changing those links but the client wants any other ones to redirect to the homepage to be safe. 很明显,我们正在更改这些链接,但是客户希望其他任何链接都重定向到主页,以确保安全。

The server is a dedicated IP and I tried this in the .htaccess file (from: Redirect IP address to domain name ): 该服务器是专用IP,我在.htaccess文件中尝试过此操作(来自: 将IP地址重定向到域名 ):

RewriteCond %{HTTP_HOST} ^121\.12\.12\.123
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I put in my credentials as well. 我也输入了凭据。 It did not work. 这没用。

Any ideas how I can accomplish this? 有什么想法我可以做到这一点吗?

Try with this : 试试这个:

RewriteCond %{HTTP_HOST} ^121\.12\.12\.123$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Ensure mod_rewrite is on. 确保打开了mod_rewrite。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM