1

In summary: (Notice the "https")

  • I have https://www.example.com
  • All need to be re-directed to https://sub.example.com
  • EXCEPT https://xyz.example.com/api

Here is my current .htaccess:

RewriteEngine On
RewriteBase /

# EXCLUDE following sub-domains.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^api\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^sub\.example\.com$ [NC]

# REDIRECT everyone to
RewriteRule (.*) https://sub.example.com/$1 [L,R=301]

BUT ... the API that is accessed via https://sub.example.com/api is BREAKING when the .htaccess is implemented! (Notice the /api folder.)

1
  • What version of Apache are you on? Is /api a filesystem directory?
    – MrWhite
    Mar 9, 2019 at 9:58

1 Answer 1

0

You can add an exception before your existing rules:

RewriteCond %{HTTP_HOST} ^xyz\.example\.com [NC]
RewriteRule ^api - [L]
5
  • Sorry ! Having trouble including blocked code in the comments section, on my MAC !! Mar 9, 2019 at 10:53
  • You mean include your code before 'RewriteCond %{HTTPS} !=on' ? Mar 9, 2019 at 11:12
  • Yes. (In one of your earlier comments (not deleted), you seemed to change xyz to api, but you already reference an api subdomain in your existing rules? Is this the same or different? If it is the same then you don't need it in both places.)
    – MrWhite
    Mar 9, 2019 at 11:36
  • You format inline code (in comments) by surrounding the code in backticks.
    – MrWhite
    Mar 9, 2019 at 11:36
  • 1
    Tested it ... that did the job ! Thanks ... Mar 9, 2019 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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