Karl Karl - 1 year ago 294
Apache Configuration Question

Apache Virtualhost Redirect Not Working

I have two simple redirects set up in my virtualhost for a subdomain; one is working, one is not:

<VirtualHost *:80>
ServerName subdomain.site.com
Redirect / https://subdomain.site.com/subdirectory/login.php

<VirtualHost x.x.x.x:443>
ServerName subdomain.site.com
Redirect / https://subdomain.site.com/subdirectory/login.php
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/subdomain.site.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/subdomain.site.com.key
ErrorLog logs/ssl_error_log
CustomLog logs/ssl_access_log common

The first redirect is working. That is, if someone simply types in subdomain.site.com in their browser it redirects to https and to the correct subdirectory. The second redirect is not working. If someone types in https://subdomain.site.com it says "Firefox has detected that the server is redirecting the request for this address in a way that will never complete" and the browser URL becomes "subdomain.site.com/subdirectory/login.phpsubdirectory/login.phpsubdirectory/login.phpsubdirectory/login.php..." instead of redirecting to the correct https://subdomain.site.com/subdirectory/login.php page. Can anyone point me in the right direction?

Edit: I updated the above VirtualHosts file to the newer version and the problem has changed so I updated the problem description as well.

Answer Source

Alright, none of the answers above worked so I had to keep working on this. Ultimately I removed the redirect line from the :443 virtualhost section and added the following two lines to the same section to get this to work correctly:

RewriteEngine On
RewriteRule ^/$ https://subdomain.site.com/subdirectory/login.php [R=301,NC,L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download