Forum Moderators: phranque
http://%{HTTP_HOST}%/auth like so RewriteRule ^/auth(.*)$ https://%{HTTP_HOST}/auth$1 [L,R,NE,QSA] https://%{HTTP_HOST}/somecontentnotauth:80, i.e. the URL has a https prefix but still the browser uses port 80. This fails (ssl_error_rx_record_too_long in FF).
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^auth
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
<VirtualHost *:80>
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} ^/auth
RewriteRule ^/auth(.*)$ https://%{SERVER_NAME}/auth$1 [R=301,L,R,NE,QSA]
...
<VirtualHost *:443>
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/auth
RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,P,L,NE,QSA] #
...
https://%{HTTP_HOST}/somecontentnotauth:80
%{SERVER_PORT} ^443$
<VirtualHost *:80>
RewriteEngine on
#
# If not an https protocol request
RewriteCond %{SERVER_PORT} !=433 [OR]
# or if explicit port number appended to HTTP_HOST request header
RewriteCond %{HTTP_HOST} :[0-9]+$
# redirect /auth requests to force https protocol
RewriteRule ^/(auth.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
...
#
<VirtualHost *:443>
RewriteEngine on
#
# If an https protocol request
RewriteCond %{SERVER_PORT} =443 [OR]
# or if explicit port number appended to HTTP_HOST request header
RewriteCond %{HTTP_HOST} :[0-9]+$
# and if not /auth request
RewriteCond %{REQUEST_URI} !^/auth
# and if not http/https shared-object request
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
# redirect to force http protocol
RewriteRule ^/(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
...
<VirtualHost *:80>
ServerAdmin webmaster@server.com
ServerName my.server.com #it indeed is on a subdomain on a different machine, could that be a problem?
RewriteEngine on
# If not an https protocol request
RewriteCond %{SERVER_PORT} !=433 [OR]
# or if explicit port number appended to HTTP_HOST request header
RewriteCond %{HTTP_HOST} :[0-9]+$
# redirect /auth requests to force https protocol
RewriteRule ^/(auth.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 9
ProxyPass / ajp://my.server.com:8009/
#Don't use proxy for gwt static content
ProxyPass /gwt !
# Aliases, dont't use proxy for these directories
Alias /gwt "/var/lib/tomcat6/webapps/ROOT/gwt"
<Directory /var/lib/tomcat6/webapps/ROOT/gwt>
Options FollowSymLinks
Allow from all
Order allow,deny
</Directory>
<Location />
ProxyPassReverse http://my.server.com/
Order allow,deny
Allow from all
#agressively cache static content (there are no static pages)
ExpiresActive On
ExpiresByType text/html "modification plus 1 year"
ExpiresByType image/gif "modification plus 1 year"
ExpiresByType image/png "modification plus 1 year"
ExpiresByType image/jpg "modification plus 1 year"
ExpiresByType application/x-javascript "modification plus 1 year"
ExpiresByType text/javascript "modification plus 1 year"
ExpiresByType text/css "modification plus 1 year"
ExpiresByType text/html "modification plus 1 year"
ExpiresByType text/xml "modification plus 1 year"
Header set Cache-Control "public, no-transform"
#enable compression
SetOutputFilter DEFLATE
# Insert filter
</Location>
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
DeflateBufferSize 259072
DeflateCompressionLevel 9
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@server.com
ServerName my.server.com
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/ssl_access.log combined
RewriteEngine on
# If an https protocol request
RewriteCond %{SERVER_PORT} =443 [OR]
# or if explicit port number appended to HTTP_HOST request header
RewriteCond %{HTTP_HOST} :[0-9]+$
# and if not /auth request
RewriteCond %{REQUEST_URI} !^/auth
# and if not http/https shared-object request
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
# redirect to force http protocol
RewriteRule ^/(.*)$ http://%{HTTP_HOST}/$1 [R=301,L,P,NE,QSA]
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 9
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://my.server.com:8009/
<Location />
ProxyPassReverse https://my.server.com/
Order allow,deny
Allow from all
</Location>
SSLEngine on
SSLCertificateFile /etc/ssl/cert/server.com.pem
SSLCertificateKeyFile /etc/ssl/private/server.com.key
SSLCertificateChainFile /etc/ssl/certs/startSSL.intermediate.sub.class1.server.ca.pem
SSLCACertificateFile /etc/apache2/ssl.crt/startSSL.root.ca.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
(2) init rewrite engine with requested uri /
(3) applying pattern '^/(auth.*)$' to uri '/'
(1) pass through /
(2) init rewrite engine with requested uri /overview
(3) applying pattern '^/(auth.*)$' to uri '/overview'
(1) pass through /overview
(2) init rewrite engine with requested uri /auth/login
(3) applying pattern '^/(auth.*)$' to uri '/auth/login'
(4) RewriteCond: input='80' pattern='!=433' => matched
(2) rewrite '/auth/login' -> 'https://my.server.com/auth/login'
(2) explicitly forcing redirect with https://my.server.com/auth/login
(1) escaping https://my.server.com/auth/login for redirect
(1) redirect to https://my.server.com/auth/login?targetUri=%252Foverview [REDIRECT/301]
(2) init rewrite engine with requested uri /auth/login
(3) applying pattern '^/(.*)$' to uri '/auth/login'
(4) RewriteCond: input='443' pattern='=443' => matched
(4) RewriteCond: input='/auth/login' pattern='!^/auth' => not-matched
(1) pass through /auth/login
(2) init rewrite engine with requested uri /auth/signIn
(3) applying pattern '^/(.*)$' to uri '/auth/signIn'
(4) RewriteCond: input='443' pattern='=443' => matched
(4) RewriteCond: input='/auth/signIn' pattern='!^/auth' => not-matched
(1) pass through /auth/signIn
(2) init rewrite engine with requested uri /
(3) applying pattern '^/(auth.*)$' to uri '/'
(1) pass through /
https://my.server.com:80/auth/%2Foverview
# redirect /auth requests to force https protocol
RewriteRule ^/(auth.*)$ https://%{HTTP_HOST}/$1 [R=301,PT,L]
# redirect to force http protocol
RewriteRule ^/(.*)$ http://%{HTTP_HOST}/$1 [R=301,PT,L]
"Bad Request
Your browser sent a request that this server could not understand."
#Don't use proxy for gwt static content
#ProxyPass /gwt !
# Aliases, dont't use proxy for these directories
#Alias /gwt "/var/lib/tomcat6/webapps/ROOT/gwt"
#<Directory /var/lib/tomcat6/webapps/ROOT/gwt>
#Options FollowSymLinks
#Allow from all
#Order allow,deny
#</Directory>
#<Location /> a2dismod alias