I have been stuck with an issue with rewrite on apache on CentOS.
If I load my site from HTTP, it works fine. Rewrite rules work. Once I change it to HTTPS, the rewrite rules don't work.
After some tests and browsing through the threads I realised that somehow apache is not picking up the .htaccess file if the website is accessed from HTTPS.
What I did to test was to insert deny from all in the .htaccess file. When I access http://my.domain.com it shows Forbidden error. When I access via https://my.domain.com I can still load the page which means .htaccess is not being read.
I've checked httpd.conf and ssl.conf and also ensured AllowOverride All is set. Is there anywhere else that I could have missed?
Here is my httpd.conf configuration:
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/httpd/ssl/my.domain.crt
SSLCertificateKeyFile /etc/httpd/ssl/my.domain.key
SSLCACertificateFile /etc/httpd/ssl/caroot.crt
ServerAdmin webmaster@domain.com
ServerName my.domain.com
ServerAlias my.domain.com
DocumentRoot /var/www/my.domain.com/public_html/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/my.domain.com/public_html/>
Options Indexes FollowSymLinks ExecCGI MultiViews
#RewriteEngine on
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/www/my.domain.com/logs/ssl-error.log
CustomLog /var/www/my.domain.com/logs/ssl-access.log combined
</VirtualHost>
And below is my .htaccess file placed inside /var/www/my.domain.com/public_html/
AddType text/x-component .htc
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Below is the config for port 80:
<VirtualHost *:80>
ServerAdmin webmaster@domain.com
ServerName my.domain.com
ServerAlias my.domain.com
DocumentRoot /var/www/my.domain.com/public_html/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/my.domain.com/public_html/>
Options Indexes FollowSymLinks ExecCGI MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/www/my.domain.com/logs/error.log
CustomLog /var/www/my.domain.com/logs/access.log combined
</VirtualHost>