0

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):

http://website.com/api/auctane

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:

http://website.com/api/auctane

to this:

https://website.com/api/auctane

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

1 Answer 1

0

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]
</Virtualhost>

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]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .