Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm more of an engineer than a devops guy, so please excuse me if this is extremely basic.

My situation: I have a server on the network, so I don't control the main DNS interface to Therefore I don't believe I can use DNSSimple or Zerigo. I do however have root on the server, and it has the following two hostnames:

My goal is to set up Apache to do the following.

  • First, when a visitor types in they should see a static webpage: -> serve up a static webpage

  • Then, if the visitor types in a URL rewrite should be executed and they should be viewing the HTTPS version of the site hosted on Heroku, as follows: -> -> ->

  • In particular, this should be a URL rewrite, so in the browser's address bar a visitor would see rather than

How do I go about this? I figure I should use Apache mod_rewrite, and edit httpd.conf. I have just started looking at tutorials, but the main tricky part is that I don't have full control over the domain and want to make sure I set things up right.

share|improve this question

Assuming you already have all the necessary Apache VirtualHost directive in place, you basically need to add the following to the port 80 and port 443 VirtualHost directives for ""... (pick one or the other)

OPTION 1: Rewrite Rule Since you indicated you were looking for a rewrite rule, I will post this, but as noted in the reference link below, it is not the best performing way to do this.

RewriteEngine on
RewriteRule ^(.*)$$1   [P]


OPTION 2: Use mod_proxy directly

ProxyPass /
ProxyPassReverse  /


... on a side note, given that the heroku app is using https (SSL), you should probably just put the proxy configuration in the port 443 (ssl) VirtualHost directive, and have the following line in the port 80 VirtualHost:

Redirect /

... which should direct your visitors to https before they start.

share|improve this answer

Apache configuration for the static site is straight forward (I have left out standard irrelevant lines)

<VirtualHost *:80>
    DocumentRoot /var/www/   

The redirect of can follow the apache guidelines for ssl redirect. I would use the built in redirect as mod_rewrite is not needed in this simple use case.

<VirtualHost *:80>
    Redirect permanent /

And for the redirection to Heroku I would use mod_proxy_http to redirect. The encrypted virtual host can be something like

ProxyRequests Off
<Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Deny from none
ProxyVia On
<VirtualHost *:443>
    SSLEngine On 
    SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
    ProxyPass /
    ProxyPassReverse  /
    ProxyPassReverseCookieDomain  /

On the Heroku side in your app source code you would create an application with:

 heroku create bar-example-edu

And configure their Custom Domain add-on with

 heroku domains:add

Adapted slightly from a section of a document I wrote regarding proxying to Heroku.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.