jndawson

Well-Known Member
Aug 27, 2014
303
32
78
Western US
cPanel Access Level
DataCenter Provider
We have a customer that posts a weather cam on their site. Their account used to be on a server that we recently decommissioned to upgrade to CentOS7/CloudLinux. Prior to the upgrade, we moved all of the accounts to another server. We have since discovered that for the past 10 or 12 years, the customer posted the weathercam link to several visitor/vacation and other sites. No issue with that; however, they used the IP address of the old server rather than their domain name:

123.123.123.123/~customerID/weathercam.jpg

This results in the 'Sorry' page and a link to our system administrator email, and the subsequent email from some anonymous person who wants to see the weather.

So, how do we redirect the IP address to the customer's domain name? Would adding a redirect to /etc/apache2/conf.d/includes/pre_virtualhost_global.conf like this work:

Code:
<VirtualHost 123.123.123.123:80>
   ServerName 123.123.123.123
   RewriteCond %{HTTP_HOST} ^.*$
   RewriteRule ^\~customerID/weathercam\.jpg$ "https\:\/\/customerdomain\.com\/" [R=301,L]
</VirtualHost>
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,296
1,266
313
Houston
You can't do this for http connections without a dedicated IP address, the default page is to be expected. Over https, the first VirtualHost in the configuration on that IP address would be displayed and that may be a solution but ultimately the way to address this is for the user to have a dedicated IP address. In that circumstance, the IP would be assigned to that user's sites and display the VirtualHost associated with their IP.
 

jndawson

Well-Known Member
Aug 27, 2014
303
32
78
Western US
cPanel Access Level
DataCenter Provider
You can't do this for http connections without a dedicated IP address, the default page is to be expected. Over https, the first VirtualHost in the configuration on that IP address would be displayed and that may be a solution but ultimately the way to address this is for the user to have a dedicated IP address. In that circumstance, the IP would be assigned to that user's sites and display the VirtualHost associated with their IP.
So, that would be, "No, you can't redirect a specific IP-based URL to a domain on another server."
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,296
1,266
313
Houston
So, that would be, "No, you can't redirect a specific IP-based URL to a domain on another server."
No, that's incorrect. You can do this for dedicated IP addresses. You can also do this over HTTPS because of Apache's default behavior for SSL VirtualHosts.

You cannot do this for a shared IP over HTTP.

If you're looking to change the default page to something else you CAN do that, you could potentially just redirect the default page itself somewhere else using a PHP redirect.

Something like the following:
Code:
            < ?php header("Location: http://www.redirect.to.url.com/"); ?>
But this would redirect ALL instances of the default page. If you want to employ this kind of redirect for the page you can do so at WHM>>Account Functions>>Web Template Editor.

mod_userdir (which is what your URL format uses) might be able to utilize this kind of redirect as well now that I think about it. If you add the PHP into the header of the page after ensuring that the page displays with mod_userdir (i.e., mod_userdir protection is not enabled at WHM>>Security Center>>Apache mod_userdir Tweak) the PHP for that redirection should function.
 

PCZero

Well-Known Member
Dec 13, 2003
712
85
178
Earth
I am reviving this thread to ask how to accomplish someting that is an extension of this issue.

How do I redirect

With or without https(s)
With or without www or any subdomain
###.###.###.###
With or without any port designator :)443)
With or without any page (index.php)

Basically redirect ANY call to the main server IP from someone browsing the web to a set URL (https://www.MyPreferredDomain.com)

Any ideas or is it even possible?

I see where peopel are calling https://###.###.###.###:443/index.php I wnat to control where that goes.