Mobile app version of vmapp.org
Login or Join
Odierno851

: Rewrite rules in .htaccess never take effect and no redirects ever happen I recently set up a vps with digital ocean to let my site run on php7 and http2 Everything is running great but my

@Odierno851

Posted in: #Apache2 #Htaccess #Redirects #Vps

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 .* example.com [L,R=301]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule .* www.example.com [L,R=301]

RewriteBase /
RewiteCond %{THE_REQUEST} ^GET.*index.php [NC]
RewriteRule (.*?)index.php/*(.*) / [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 example.com ServerAlias 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 phillip@example.com
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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Odierno851

1 Comments

Sorted by latest first Latest Oldest Best

 

@Cody1181609

I finally figured it out and it was really simple. Instead of modifying my sites virtual hosts I file modified my apache2.conf file located at /etc/apache2/apache2.conf as such

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


Took me a while to get there but simple when you know how! Thanks for all your help

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme