I’m trying to do something really simple here but it’s kicking my butt haha. I have my website, and I got a SSL certificate for it this morning. I want my users to be redirected to the secure site, but I only need the certificate for a certain portion of my website so I don’t want to worry about everywhere else. The certificate is made to domain.com not www.domain.com. The part of my website where I need the certificate, all of the pages are in the apps directory. For example domain.com/apps/login.php. Here is what I have been putting in my .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/apps/.*$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://domain\.com%{REQUEST_URI} [R=301,L]
Now I will explain what I think this should be doing and I would like to be told where I’m wrong haha.
RewriteEngin On– Allows redirectsRewriteCond %{REQUEST_URI} ^/apps/.*$– Checks if user is in the apps directoryRewriteCond %{HTTPS} !=on– Checks if user is already using https://RewriteRule ^(.*)$ https://domain\.com%{REQUEST_URI} [R=301,L]– Redirect
This partially works. When I type in www.domain.com/apps/login.php it redirects to https://domain.com/apps/login.php. Perfect. But if I just type in www.domain.com it redirects to https://domain.com. So it seems that my line RewriteCond %{REQUEST_URI} ^/apps/.*$ is broken. What do I need to put there to make it so that it only redirects to the secure site when they are in the apps directory?
Your rule looks to me like it should work, but in any case you don’t need the
RewriteCond %{REQUEST_URI}test. Just include^appsin theRewriteRule: