Hi, I have a virtual host with a <VirtualHost> section like this: NameVirtualHost * <VirtualHost *> CheckSpelling on ServerName server.macalester.edu DocumentRoot "/var/www/server/htdocs" RewriteEngine on RewriteLogLevel 2 RewriteLog "/usr/local/apache/logs/server.mac.edu.rewrite.log" RewriteMap lowercase int:tolower RewriteRule (.*) ${lowercase:$1} [PT] </VirtualHost>
I need to force all accesses to a particular directory (and subdirs) to https, e.g. http://server.macalester.edu/restricted and http://server.macalester.edu/restricted/anything/at/all should be rewritten as https://server.macalester.edu/restricted and https://server.macalester.edu/restricted/anything/at/all ...respectively. I've read the FAQ and mod_rewrite guide but am not having luck. I've used mod_rewrite before to do https rewrites, but not quite like this, and I can't get it to work. I've tried this: <VirtualHost *> CheckSpelling on ServerName server.macalester.edu DocumentRoot "/var/www/server/htdocs" RewriteEngine on RewriteLogLevel 2 RewriteLog "/usr/local/apache/logs/server.mac.edu.rewrite.log" RewriteCond %{SERVER_PORT} !^443$ RewriteCond %{REQUEST_URI} ^/restricted(.*)$ [NC] RewriteRule ^/restricted(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,NC] RewriteMap lowercase int:tolower RewriteRule (.*) ${lowercase:$1} [PT] </VirtualHost> Then in the mod_rewrite log, I see messages like: rewrite /restricted/ -> https://server.macalester.edu/restricted/ (ok, good) But then I see rewrite https://server.macalester.edu/restricted/ -> https://server.macalester.edu/restricted/ ...which is bad because that is a useless rewrite, and maybe an infinite loop. I *thought* the RewriteCond statements had an implicit [AND] after them, so I thought my rules above would translate to: If the server port is not 443, and the requested URI starts with "restricted" then rewrite the request as https. Apparently that is not what it means. What am I doing wrong? Help! and Thanks, Ted