Forum Moderators: phranque
For my main www domain I have
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) [mydomain.com...] [L,R]
I have created a wiki.mydomain.com and I am doing this to redirect:
RewriteRule "^/WEB-INF/?(.*)" "$0" [L,F,NC]
RewriteRule "^/$" [localhost:8888...] [P]
RewriteRule "^/(.*)" "http://localhost:8888/$1" [P]
ProxyRequests Off
ProxyPassReverse / [localhost:8888...]
ProxyPreserveHost On
This all works except if I go to [wiki.mydomain.com...] I get my main secure site. I tried this above my redirect to localhost redirect:
#RewriteCond %{SERVER_PORT} ^80$
#RewriteRule ^/(.*) [wiki.mydomain.com...] [L,R]
And that does not work either. Can anyone suggest how I can fix this issue?
The problem is that an https request that lands in your SSL host is NOT going to have a server port of 80; By definition it'll be 443. So, you need to check the requested hostname instead:
RewriteCond %{HTTP_HOST} ^wiki\.example\.com
RewriteRule ^/(.*) http://wiki.example.com/$1 [R=301,L]
[edited by: jdMorgan at 2:20 am (utc) on Jan. 13, 2009]
I added the following to my httpd.conf:
RewriteCond %{HTTP_HOST} ^wiki\.mydomain\.com
RewriteRule ^/(.*) [wiki.mydomain.com...] [R=301,L]
I get this error from firefox:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept cookies.
Here is the complete virtual host entry just in case:
<VirtualHost #*$!.#*$!.#*$!.#*$!:80>
ServerName wiki.mydomain.com
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^wiki\.mydomain\.com
#RewriteRule ^/(.*) [wiki.mydomain.com...] [R,L]
RewriteRule "^/WEB-INF/?(.*)" "$0" [L,F,NC]
RewriteRule "^/$" [localhost:8888...] [P]
RewriteRule "^/(.*)" "http://localhost:8888/$1" [P]
ProxyRequests Off
ProxyPassReverse / [localhost:8888...]
ProxyPreserveHost On
ErrorLog /var/log/httpd/wiki-error_log
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
TransferLog /var/log/httpd/wiki-access_log
ServerAdmin webmaster@mydomain.com
ServerSignature On
</VirtualHost>
The only redirect I do for the main domain www is:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) [mydomain.com...] [L,R]
If needed I can include my complete Vhost for that domain as well.
You have two variables that must be accounted for in the redirect/don't domain redirect decision, the hostname and the port number. Both of these have to be taken into account, either by the RewriteConds in the code itself, or by the containers (e.g. <VirtualHost> or <Directory> ) in which the code is placed.
So this wiki-to-http redirect code needs to go into the <VirtualHost w.x.y.z:443> container.
Jim
<VirtualHost w.x.y.z:80>
ServerName www.mydomain.com (side question can I have mydomain.com here as well)
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) [mydomain.com...] [L,R]
RewriteRule ^/(.*) [mydomain.com...] [L,R]
...
</VirtualHost>
I only have the one vhost for port 80.
So from what I understand is that I should have 2 vhost one for 80 and one for 443.
<VirtualHost w.x.y.z:443>
ServerName www.mydomain.com
RewriteCond %{HTTP_HOST} ^wiki\.example\.com
RewriteRule ^/(.*) [wiki.example.com...] [R=301,L]
</VirtualHost>
And the final vhost (wiki) would be
<VirtualHost w.x.y.z:80>
ServerName wiki.mydomain.com
RewriteEngine On
--------------------
is this needed here
--------------------
#RewriteCond %{HTTP_HOST} ^wiki\.mydomain\.com
#RewriteRule ^/(.*) [wiki.mydomain.com...] [R,L]
--------------------
END
--------------------
RewriteRule "^/WEB-INF/?(.*)" "$0" [L,F,NC]
RewriteRule "^/$" [localhost:8888...] [P]
RewriteRule "^/(.*)" "http://localhost:8888/$1" [P]
ProxyRequests Off
ProxyPassReverse / [localhost:8888...]
ProxyPreserveHost On
ErrorLog /var/log/httpd/wiki-error_log
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
TransferLog /var/log/httpd/wiki-access_log
ServerAdmin webmaster@mydomain.com
ServerSignature On
</VirtualHost>
RewriteCond %{HTTP_HOST} ^wiki\.example\.com
RewriteRule ^/(.*) [wiki.example.com...] [R=301,L]
Look at just these four lines. It should be clear that this code will always execute, because if the port is 80, then it will always be "NOT 443":
<VirtualHost w.x.y.z:[b]80[/b]>
ServerName www.mydomain.com
RewriteCond %{SERVER_PORT} [b]!^443$[/b]
RewriteRule ^/(.*) https://www.mydomain.com/$1 [L,R]
As for your question about "having 'mydomain.com' here as well," you can use the ServerAlias directive.
Jim