Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite problem or DNS?

         

Donboy

2:17 am on Jul 14, 2005 (gmt 0)

10+ Year Member



I hate even asking about this because mod_rewrite has been covered so extensively on this site, but I'm having trouble making this work when I feel it should.

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?

jdMorgan

2:35 am on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main problem appears to be that there is nothing to stop the rule from being reapplied *after* you have already rewritten to https, and that's probably why you get a timeout -- it's redirecting repeatedly.

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]

Jim

Donboy

5:34 am on Jul 14, 2005 (gmt 0)

10+ Year Member



Hmmm, doesn't seem to be working. I used what you had in both httpd.conf and ssl.conf and it still doesn't want to go. I get timeouts for....

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>

Donboy

11:55 am on Jul 19, 2005 (gmt 0)

10+ Year Member



Anyone? I'm still horribly stuck on this problem.