I'm forcing http to https with the following in .htaccess:

## Forcing https
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://website.com/$1 [R,L]

Following that, I also have a redirect that redirects users from the web root of this site to a subdirectory:

RedirectMatch ^/$ /subdirectory/

One of the problems I'm experiencing is that when I have the HTTPS redirect above enabled, the following URL doesn't work (among others):


It just redirects to https://website.com/subdirectory.

So I'm having to leave off the forced HTTPS just to allow access to the API URL.

My question: What would it take to redirect this:


to this:


Or to only redirect users to HTTPS if they specifically go to webroot http://website.com/


If you have access to modify your vhosts then you might find it cleanest to do it there. The vhost that's listening on port 80 should just do a single rewrite rule that would redirect everything immediately to https:

<Virtualhost website.com:80>
    RewriteEngine on
    RewriteRule ^(.*)$ https://website.com$1 [R=301,L]

Since that vhost will only see URL's for HTTP (port 80) you just blindly redirect the entire URL to HTTPS.

If you need to do this in your .htaccess file then something like this should work. It's similar to the above but the RewriteCond is telling it to look only at HTTP traffic.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.