Warning: This article is considered legacy. It is either obsolete or references old unmaintained software. Please use your best judgement as to the relevancy of this article.

Adding a HTTP Redirect to your website is something that needs to be done on your backend.

Using Apache

You need to add a .htaccess or modify an existing one, the code would be something like this. You need mod_rewrite for this:

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 [R01,L]

Using Nginx

In your sites nginx configuration file:

return 302 https://www.mydomain.com$request_uri #Redirect to mydomain.com/1 to www.mydomain.com/1

Using PHP

header('Location: https://www.mydomain.com/',true,302);