Сайт Apache не загружается без http или https перед ним - PullRequest
0 голосов
/ 05 июля 2019

, если я не включаю префикс http: // или https: //, мой сайт не загружается.

Например, они не загружаются: example.com, www.example.com

Но это делает: https://example.com, http://example.com, http://www.example.com, https://www.example.com

Я использую Apache в качестве своего веб-сервера, и вот мой доступный для сайтов conf:

<VirtualHost *:80>
        ServerAdmin
        DocumentRoot /var/www/html
        ServerName example.com
        ServerAlias www.example.com

        <Directory /var/www/html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

У меня есть сертификат SSL, сгенерированный certbot.

Есть идеи, почему это происходит?

Заранее спасибо

1 Ответ

0 голосов
/ 05 июля 2019

вы можете попробовать это

<VirtualHost *:80>
    ServerAdmin
    DocumentRoot /var/www/html
    ServerName example.com
    ServerAlias www.example.com

    <Directory /var/www/html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
    </IfModule>

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://{SERVER_NAME}%{REQUEST_URI} [L,NE,R=301]

...