Phil Cross
Phil Cross

Reputation: 9302

Mod Rewrite - multiple condition

I have a certain sub-domain which requires an SSL connection for all pages on that subdomain.

This is my current .htaccess script:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

I have a single page on the subdomain which must not have SSL access (causes issues with accessing files on another server without a certificate).

My mod_rewrite knowledge is very limited. I've done a search but can't find what I need.

My question is, the page which must not have https is called 'tutorial.php'. Is there a way to redirect all pages except tutorial.php to https?

I guess in pseudo-code, the RewriteCond would be similar to:

RewriteCond %{SERVER_PORT} 80 AND {WEB_PAGE}!='tutorial.php'

Thanks

Upvotes: 0

Views: 78

Answers (1)

Jon Lin
Jon Lin

Reputation: 143946

Try this:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/tutorial\.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

RewriteCond %{HTTPS} on
RewriteRule ^tutorial\.php$ http://%{HTTP_HOST}/tutorial.php [R,L]

Upvotes: 1

Related Questions