Назад | Перейти на главную страницу

ubuntu - apache - виртуальный хост не обрабатывает mod_rewrite

У меня есть экземпляр AWS EC2 с установленными Ubuntu и Apache.

Трафик к этому экземпляру всегда проходит через порт 80, поскольку перед ним находится балансировщик нагрузки, который обрабатывает запрос https.

Я хочу убедиться, что даже если кто-то попытается просмотреть его через обычный http, он будет автоматически перенаправлен на тот же URL-адрес, что и https.

Это мой .htaccess:

Options -Indexes

#Set the response headers
<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
   Header set Access-Control-Allow-Methods "*"
</IfModule>


<IfModule mod_rewrite.c>
    #Enable the Rewrite Engine
    RewriteEngine On

    #Redirect to the Https site always.
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


</IfModule>

это файл конфигурации виртуального хоста:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin admin@my_domain.com

    ServerName dev_brands.my_domain.com

    ServerAlias new_dev_brands.my_domain.com

    DocumentRoot /var/www/dev_brands.my_domain.com/public_html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

<Directory /var/www/dev_brands.my_domain.com>
       AllowOverride All
</Directory>

Я знаю файл ..htaccess, если он обрабатывается, так как если я просто наберу случайный текст - это вызовет ошибку 500.

Даже когда я пытаюсь перенаправить трафик только в Google - не работает.