A
A
avp2018-05-30 15:25:59
linux
avp, 2018-05-30 15:25:59

Trouble redirecting from http to https?

The redirect only works from the site root.
httpd.conf

<VirtualHost *:80>
    DocumentRoot /var/www/html/example.com
    ServerName example.com
    Redirect / https://example.com

</VirtualHost>

<VirtualHost *:443>
    DocumentRoot /var/www/html/example.com
    ServerName example.com

    SSLEngine on

    # SSLRequireSSL
    # SSLVerifyClient require

    SSLCACertificateFile /usr/local/ssl/crt/comodo.crt

    #ServerAlias www.example.com
    <Directory "/var/www/html/example.com">
        allow from all
        Options None
        Require all granted
    </Directory>

    ErrorLog /var/www/html/example.com/error.log

    php_admin_flag register_globals 1
    php_admin_value max_execution_time 60
    php_admin_value upload_max_filesize 10M
    Include /etc/letsencrypt/options-ssl-apache.conf
    ServerAlias www.example.com
    SSLCertificateFile /etc/letsencrypt/live/example.com-0001/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com-0001/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com-0001/chain.pem
</VirtualHost>

.htaccess
ErrorDocument 403 /403
# Disable magic quotes
php_flag magic_quotes_gpc 0
php_flag magic_quotes_runtime 0

# Turn on URL rewriting
RewriteEngine On

Options -Indexes
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Installation directory
RewriteBase /

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php?q=$0

AddDefaultCharset UTF-8
<Files config.php>
deny from all
</Files>
<Files M*.php>
deny from all
</Files>
<Files C*.php>
deny from all
</Files>
<Files v*.php>
deny from all
</Files>
AddType application/octet-stream .txt
AddType application/octet-stream .exe
AddType application/octet-stream .npk
AddType application/octet-stream .rsc
AddType application/octet-stream .xls
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grishin, 2018-05-30
@vesper-bot

Move the HTTPS RewriteRule, along with its condition, above the rest of the RewriteRule rules. At first, the HTTP_HOST www rule is processed for you, and the L flag on it is to stop processing the rules below.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question