1

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>
4
  • Strange. Can you also post the :80 virtual host for comparison? – JayMcTee Jul 8 '15 at 22:00
  • I've updated my question with port 80 config. – darnpunk Jul 9 '15 at 2:42
  • No actual errors in the logs? Is there another default virtualhost? If you change the :433 docroot to add /test/ at the end and put a test index.html in there, does it resolve to that path? – JayMcTee Jul 9 '15 at 9:53
  • @JayMcTee When I added a /test it doesn't show any error. And then I looked into ssl.conf and noticed the defaults are set there which shares the same ServerName and ServerAlias as my.domain.com. I placed the <Directory> settings above into that file and reloaded httpd. It works perfectly now! Thanks :) – darnpunk Jul 10 '15 at 2:45
0

Turning my comment into an/the answer then:

Is there another default virtualhost? As everything you've shown seems correct, I suspect there is something else preventing this from working correctly. Most likely, default conf files and/or their default settings.

Check the default settings in ssl.conf, especially ServerName and ServerAlias. Also httpd.conf

0

Make sure, that your global Apache configuration has the below line:

AccessFileName .htaccess

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.