ewizard
ewizard

Reputation: 2862

VirtualHost not redirecting

I am trying to redirect http://eamondev.com:3000 to https://omniatm.eamondev.com with a VirtualHost. I am using node to serve a site to http://eamondev.com:3000. I am using vhost with node like this:

app.use(vhost('omniatm.eamondev.com', express.static('/')));

I have never used vhost and it took me a while to figure this out without having to split up all my code like I was working with more than one site (when I am not), so I'm not sure if it is exactly how it should be for an Apache redirect to work.

In my apache conf file I have:

<VirtualHost *:80>
ServerName omniatm.eamondev.com
ProxyPreserveHost on
ProxyPass / http://localhost:3000/
</VirtualHost>

I am also using WHM on a VPS, I'm not sure if this is relevant or not, but the ServerName (with protocol, what I type into the browser) needs to be https://omniatm.eamondev.com.

I cannot serve node on port 80 of my server (and then redirect to subdomain) because my main site (http://eamondev.com) is running on port 80.

I have referenced most of the stackoverflow questions about this and nothing has worked. I should mention (although I'm not sure exactly how it is relevant, I just saw it in a stackoverflow question I looked at), my hosting support (bluehost) used WHM to set things up with a wildcard ssl certificate to make the omniatm.eamondev.com subdomain https.

How do I redirect http://eamondev.com:3000 to https://omniatm.eamondev.com using apache (or vhost)?

Upvotes: 4

Views: 465

Answers (1)

Jeevan
Jeevan

Reputation: 319

Proxy passing as given in the question will not do any redirects instead it will retain the URL as such and proxy the content from elsewhere. In Apache configuration, we have an option to do redirects, in the bellow sample, we are checking for the host and based on it issuing an redirect to the desired URL

<VirtualHost *:80>
    ServerName omniatm.eamondev.com
    Redirect / https://omniatm.eamondev.com
    <If "%{HTTP_HOST} != 'eamondev.com:3000'">
     Redirect "^/?(.*)"  "https://omniatm.eamondev.com/$1"
   </If>
</VirtualHost>

Upvotes: 1

Related Questions