How do I redirect http to http except one URL?


#1

Hi,
I’m trying to redirect all http traffic to https, except the one to the stats URL. That stats URL is reached through the control panel and is basically http://yourdomain.com/stats/

I currently have this in my .htaccess file at the site root, based on looking at other threads here and on the internet.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.) https://%{HTTP_HOST}%{REQUEST_URI} [NC]
RedirectMatch (.
)/$ $1/index.html

However, I can’t seem to find a pattern that works for the /stats/ URL. Can anybody help?

Thanks.


#2

try

RewriteCond %{REQUEST_URI} !/stats$


#3

Based on your suggestion, I have this in my .htaccess file now, but it does not work.

Options -Indexes
ErrorDocument 404 /error.html
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/stats$
RewriteRule (.) https://%{HTTP_HOST}%{REQUEST_URI} [NC]
RedirectMatch (.
)/$ $1/index.html

All http requests are routed to https, but if I do http://yourdomain.com/stats, http://yourdomain.com/stats/, http://www.yourdomain.com/stats, or http://www.yourdomain.com/stats/, it tries to point to a failed_auth.html page.

The stats page requires authentication, so is that a reason why the redirect fails?


#4

I received an answer from Dreamhost support.

I needed a second RewriteCond to cover the stats folder and also the failed_auth.html file.