Search code examples
wordpressapache.htaccess

Wordpress .htaccess acting weird


I created a WP site in WP Local and was just testing the deployment process. I exported it using WP Local itself and uploaded the app/public folder which contain the wp-admin, wp-content, wp-includes and all of its files.

Configure wp-config for the db connection, manually set my siteurl & home to match the domain (atm, its a subdomain so I use this one). It's also SSL through cloudflare so I'm using https:// as prefix.

I went into admin panel, settings - general and checked the URL for home and site and clicked save just to be certain for cache. Then I went settings - permanlinks and saved all there.

Result -> Homepage works, others don't (wp-admin does) so I thought my mod rewrite was not working.

Mod rewrite module is activated and these are my apache conf:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName subdomain.domain.be
    DocumentRoot /var/www/wp-root-path

    <Directory /var/www/wp-root-path>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>

    ErrorLog ${APACHE_LOG_DIR}/subdomain.domain.be.error.log
    CustomLog ${APACHE_LOG_DIR}/subdomain.domain.be.access.log combined
</VirtualHost>
<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName subdomain.domain.be
    DocumentRoot /var/www/subdomain.domain.be
    ErrorLog ${APACHE_LOG_DIR}/subdomain.domain.be.error.log
    CustomLog ${APACHE_LOG_DIR}/subdomain.domain.be.access.log combined

    SSLEngine on
    SSLCertificateFile /etc/cloudflare/path-to-cloudflare.pem
    SSLCertificateKeyFile /etc/cloudflare/path-to-cloudflare.key
</VirtualHost>

I tried change permalink settings, deleting the .htaccess file (on save it regenerated it), the permissions of the .htaccess is 644..

Everything looks good to me, yet it isn't? Any tips? Thanks in advance!


Solution

  • DocumentRoot /var/www/wp-root-path
    
    <Directory /var/www/wp-root-path>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>
    

    Your <VirtualHost *:443> container seems to be missing half the necessary config directives?

    Your vHost:443 container is setting a different DocumentRoot? You are also failing to allow .htaccess overrides in the vHost:443 container so any "pretty" permalinks are going to fail (404). And you are not permitting access either.

    I would assume you are on Apache 2.4 (not Apache 2.2), so you should be using Require all granted, instead of the deprecated Order and Allow directives.

    You are also missing the SetHandler directive in the vHost:443 container?