LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Http to https redirect for non-virtual host (https://www.linuxquestions.org/questions/linux-server-73/http-to-https-redirect-for-non-virtual-host-4175650811/)

kenmore 03-24-2019 03:44 PM

Http to https redirect for non-virtual host
 
I want to redirect http requests to https in an Apache server by modifying the http.conf file as opposed to adding a .htaccess file. All examples I have found pertain to virtual hosts. I have vitual hosts but the domain I want redirection on is not a virtual host. It is the server name. How can I redirect?

scasey 03-24-2019 05:15 PM

Quote:

Originally Posted by kenmore (Post 5977355)
I want to redirect http requests to https in an Apache server by modifying the http.conf file as opposed to adding a .htaccess file. All examples I have found pertain to virtual hosts. I have virtual hosts but the domain I want redirection on is not a virtual host. It is the server name. How can I redirect?

Where is the domain's ServerName defined in the httpd.conf if not in a virtual host container?
In the " 'Main' server configuration"?

Put the Redirect directive in the same place as the ServerName directive, and you will need to also have a https defined for that ServerName, typically in another VirtualHost container for port 443.

We have the "main" server name defined as the first VirtualHost container, because any requests to the server that don't match any other ServerName will default to the first VirtualHost.

kenmore 03-26-2019 09:16 AM

I placed the following line in the httpd.conf file just below the server name line in the main server configuration:

Redirect "/" "https://www.mydomain.com/"

Its forwarding http for mydomain to https but its also forwarding my virtual host damains to "mydomain".

How do I prevent the latter?

scasey 03-26-2019 10:52 AM

Quote:

Originally Posted by kenmore (Post 5977950)
I placed the following line in the httpd.conf file just below the server name line in the main server configuration:

Redirect "/" "https://www.mydomain.com/"

Its forwarding http for mydomain to https but its also forwarding my virtual host damains to "mydomain".

How do I prevent the latter?

1. Put (move) mydomain.com into a VirtualHost. If it's the first VirtualHost, it will be the "default" if the server is called by IP.
2. Code your Redirect to only redirect that domain.
I'm not absolutely sure of the syntax...something like
Code:

Redirect permanent "/mydomain.com" "https://www.mydomain.com/"
We do the first.

Edit: Here's a link to the documentation


All times are GMT -5. The time now is 09:03 PM.