LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-24-2019, 03:44 PM   #1
kenmore
LQ Newbie
 
Registered: Mar 2019
Posts: 8

Rep: Reputation: Disabled
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?
 
Old 03-24-2019, 05:15 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by kenmore View Post
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.
 
Old 03-26-2019, 09:16 AM   #3
kenmore
LQ Newbie
 
Registered: Mar 2019
Posts: 8

Original Poster
Rep: Reputation: Disabled
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?
 
Old 03-26-2019, 10:52 AM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by kenmore View Post
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

Last edited by scasey; 03-26-2019 at 10:53 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Virtual host site is very slow on https but fast on http vicky219 Linux - Server 1 07-07-2017 08:35 AM
Apache Virtual host site is very slow on https but fast on http vicky219 Linux - Server 5 07-07-2017 03:55 AM
redirect https://www.domain.com to https://domain.com decenter Linux - Server 4 09-13-2011 10:05 AM
apache 2.0 https to https redirect struct Linux - Software 1 04-22-2011 05:43 PM
Apache 2 / SSL and virtual host under GNU/Linux Debian Etch - http and https scls19fr Linux - Server 0 10-09-2008 10:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration