Forum Moderators: phranque
What I'd like to do is have all requests given to a server rewrite the URL to https instead. I have this working on another server, but it won't work on this one. Here's the rule I have...
RewriteEngine on
RewriteCond %{HTTP_HOST}!^mail.mydomain.com
RewriteRule ^/(.*)$ [mail.mydomain.com...] [R=301,L]
WHAT I WANT TO DO:
I want all requests to be rewritten to [mail.mydomain.com....] For example, if somebody types in mail.theirdomain.com, I want them to be rewritten to [mail.mydomain.com...] instead.
WHAT ACTUALLY HAPPENS:
When I put in mail.mydomain.com or mail.theirdomain.com, I get a "timeout" error. If I put in [mail.theirdomain.com,...] I get an error about the SSL certificate not matching the domain. As soon as I click OK to the error, it performs the rewrite and the address bar looks correct. The only way it works perfectly is if I put in [mail.mydomain.com,...] in which case I don't get any errors.
The above rules are located in both ssl.conf and httpd.conf in the virtual hosts section.
Any ideas what could be wrong here?
Try something like this:
RewriteEngine on
# If request is for subdomain 'mail.'
RewriteCond %{HTTP_HOST} ^mail\.
# but not for 'mail.mydomain.com'
RewriteCond %{HTTP_HOST} !^mail\.mydomain\.com [OR]
# or not using a secure connection
RewriteCond %{SERVER_PORT} !^443$
# then redirect to https
RewriteRule ^/(.*)$ https://mail.mydomain.com/$1 [R=301,L]
mail.theirdomain.com
mail.mydomain.com
[mail.theirdomain.com...]
[mail.mydomain.com...]
Now, if I put in [mail.theirdomain.com,...] it will rewrite correctly to [mail.mydomain.com,...] which is a step in the right direction. I think there is something wrong with the http side, because it seems like any calls to the httpd.conf file are giving me the timeouts.
Don't know if this is relevent, but here is my virtualhost section for the httpd.conf...
<VirtualHost 192.168.0.60>
ServerAdmin donboy@mydomain.com
DocumentRoot /home/me/www/html
ServerName mydomain.com
ServerAlias *.mydomain.com
ErrorLog /home/me/www/logs/errors.log
CustomLog /home/me/www/logs/access.log common
CustomLog /home/me/www/logs/referer.log referer
CustomLog /home/me/www/logs/agent.log agent
ScriptAlias /cgi-bin/ "/home/me/www/html/cgi-bin/"
RewriteEngine on
# If request is for subdomain 'mail.'
RewriteCond %{HTTP_HOST} ^mail\.
# but not for 'mail.mydomain.com'
RewriteCond %{HTTP_HOST}!^mail\.mydomain.com [OR]
# or not using a secure connection
RewriteCond %{SERVER_PORT}!^443$
# then redirect to https
RewriteRule ^/(.*)$ https://mail.mydomain.com/$1 [R=301,L]
</VirtualHost>