I use Sakura Internet Server
Three sites are managed in the following directory.
Initial domain
-Domain 1
ー ー ー public_html ー index.html
-Domain 2
-Domain 3

I want to redirect to domain 1 of these
See [https://www.garunimo.com/program/p35.php]
The following htaccess was installed in the www folder.

Redirect/"https: //www.domain name"
RewriteEngine On
RewriteCond% {HTTPS} off
RewriteRule. * Https: //% {HTTP_HOST}% {REQUEST_URI} [L, R = 301]
RewriteCond% {HTTP_HOST}! ^ Www \. [NC]
RewriteRule. * Https: //www.% {HTTP_HOST}% {REQUEST_URI} [L, R = 301]
RewriteCond% {THE_REQUEST} ^. */Index.html
RewriteRule ^ (. *) Index.html $https: //www.% {HTTP_HOST}% {REQUEST_URI} [R = 301, L]

I was expecting

  1. http: // domain 1
  2. http: //domain1/index.html
  3. http: //www.domain1/index.html
  4. https: // domain 1
  5. https: //www.domain1/index.html
    To the above address
  • with www
  • index.html is omitted
  • Jump to a page that supports SSL (certificate is already obtained)
    It is the operation.

But current status
(2) http: //domain1/index.html
(5) https: //www.domain1/index.html
Only these two,
https: //www.domain name domain 1/public_html/will be accessed.
(Due to the first Redirect declaration?)

I am stuck without knowing if the location of htaccess is bad or the content is bad.
I can't understand htaccess, and I'm really not good at it.

  • Answer # 1

    RewriteRule is regular expression based filtering. And since the OR condition flag is not given,
    In the current situation, it is sieved in order by the cumulative AND condition. However, if there is a gap and only the last condition is passed, it will pass through.

    RewriteCond% {HTTPS} off
    RewriteRule. * Https: //% {HTTP_HOST}% {REQUEST_URI} [L, R = 301]

    (1) (2) (3) passes and (4) and (5) are sieved off.

    RewriteCond% {HTTP_HOST}! ^ www \. [NC]
    RewriteRule. * Https: //www.% {HTTP_HOST}% {REQUEST_URI} [L, R = 301]

    Since (4) and (5) are sieved with A,! ^ wwwdoes not add www (1) (2) passes and (3) sieves Will be dropped.

    RewriteCond% {THE_REQUEST} ^. */index.html
    RewriteRule ^ (. *) Index.html $https: //www.% {HTTP_HOST}% {REQUEST_URI} [R = 301, L]

    Here, only (3) is screened, and (4) and (5), which should have been screened by A, are also the targets. For (1), (2), (4), and (5), index. Filtered by whether html exists. See the link below to see why this happens.

    (1) Since it does not end with index.html, it will be screened out.
    (2) Pass through B and end withindex.html.
    (3) Screened with B.
    (4) Since it does not end with index.html, it is screened out.
    (5) Although it is sieved off by A, it passes because it ends withindex.html.

    Therefore, only (2) and (5) pass through.

    In order to avoid thisWhy this happenedstate, I recommend using an OR condition instead of an AND condition.

    RewriteCond% {HTTP_HOST}! ^ www \. [NC | OR]
    RewriteRule. * Https: //www.% {HTTP_HOST}% {REQUEST_URI} [L, R = 301]

    ● OR condition reference link ↓
    Basic knowledge of Apache RewriteCond
    ● Reference page for process distribution
    When writing RewriteRule in .htaccess, even if [L] flag is added, it may not end there. Talk.