0
votes

Need some help writing a re-write rule in apache v2.4.

I have a web app which is hosted in tomcat v8.0.29 which has this url:

http://myapptest:8080/app

Through the magic of mod_jk and the apache rewrite engine, I've been able to clean that up to just http://myapptest.

I now have SSL configured in apache and I need http://myapptest and https://myapptest to get redirected to https://myapptest.domain.com.

In httpd-ssl.conf, I have this vhost configuration which handles the rewrite stuff:

<VirtualHost _default_:443>
  ServerName myapptest
  RewriteEngine on    
  RewriteRule   ^/$ /app [NC,PT,L]    
  DocumentRoot "c:/apache/tomcat/webapps/app"
  JkMount /* myapp          
  ErrorLog "logs/myapptest-error.log"
  CustomLog "logs/myapptest-access.log" common
  ...other stuff...
</VirtualHost>

Then, in httpd-vhosts.conf I'm handling the redirection for the http traffic on port 80.

<VirtualHost myapptest:80> 
    ServerName myapptest
    Redirect      /   https://myapptest.domain.com/
</VirtualHost>

The last piece I'm missing is how to handle the redirect for https://myapptest?

If there is a better, cleaner way to handle this I am very open to that as I'm not an expert on this stuff.

1

1 Answers

0
votes

Avoid a hostname inside the VirtualHost tag:

# First listed is the default for port 80
<VirtualHost *:80> 
    ServerName myapptest.domain.com
</VirtualHost>

# Capture the short hostname and redirect to FQDN
<VirtualHost *:80> 
    ServerName myapptest
    Redirect      /   https://myapptest.domain.com/
</VirtualHost>