I recently set up a vps with digital ocean to let my site run on php7 and http2 Everything is running great but my sites .htaccess file is not redirecting as it should. I have changed up my 000-default.conf and my apache2.conf files to allow .htaccess to work!
This is what I have in my .htaccess file
#ExpiresActive On
#ExpiresByType image/gif "now plus 9 years"
#ExpiresByType image/png "now plus 9 years"
#ExpiresByType image/jpeg "now plus 9 years"
#ExpiresByType image/x-icon "now plus 9 years"
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule .* https://example.com [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.example.com [L,R=301]
RewriteBase /
RewiteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$1 [R=301,NE,L]
On my other shared hosting this file worked fine and I know this file is working because if I uncomment all of the ExpiresByType it breaks my site so I will probably take those out! Also the index.php does not redirect. Have I missed something somewhere?
Have been told that my question is unclear so will provide my sites .conf file.
DirectoryIndex index.php
<LocationMatch "^(.*\.php)$">
ProxyPass fcgi://127.0.0.1:9000/var/www/example.com/public_html
</LocationMatch>
NameVirtualHost *:443
<VirtualHost *:443>
AccessFileName .htaccess
ServerName www.example.com
ServerAlias www.example.com
SSLEngine on
SSLCertificateFile "/etc/letsencrypt/live/example.com/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/example.com/privkey.pem"
SSLCertificateChainFile "/etc/letsencrypt/live/example.com/chain.pem"
Protocols h2 http/1.1
H2Direct on
ServerAdmin [email protected]
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I can also confirm that sudo a2enmod rewrite is enabled. Hope this clears things up.
/sites-enabled/
and details if you have or not enabled mod_write usingsudo a2enmod rewrite
.