2

I have a VPS server with Apache, FastCGI and php-fpm installed. But, the .htaccess files seems be ignored. I have a .htaccess file that redirects http URLs to https URLs:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
</IfModule>

But the rules are ignored and no redirect happens.

Here is my virtual host file (I changed the domain to example.com):

<VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/example.com/public

        <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>

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

        Include /etc/apache2/conf-available/php7.0-fpm.conf
</VirtualHost>

The apache rewrite module seems be enabled. When I run sudo apache2ctl -M, the rewrite_module (shared) is showed on output.

Any help will be very appreciated. Thanks.

user3753202
  • 121
  • 3
  • 1
    Is `AllowOverride` set correctly in the config? – Sven Jul 28 '18 at 18:07
  • @Sven, yes. AllowOverride is setted as All in the virtual host. – user3753202 Jul 28 '18 at 18:50
  • Have you found a solution for this? – Curious Mind Oct 31 '18 at 16:55
  • You should change the directory path to `` to limit the scope of the virtual host. As it stands, it is allowing Apache to grant access to your server's root `/` directory. See: [Apache Security Tips](https://httpd.apache.org/docs/2.4/misc/security_tips.html#protectserverfiles) Please post your `php7.0-fpm.conf`. – Will B. Nov 04 '18 at 01:15

0 Answers0