KBBx
KBBx

Reputation: 21

Wordpress blog with Symfony app - Apache Alias config

I have a Symfony app and I want run Wordpress on the subdirectory /blog. The Wordpress installation is on its own directory, not in the web folder of Symfony.

The problem is that Wordpress doesn't execute the index.php file and when I go to myweb.com/blog i see the "Index Of" page with a list of all wordpress folder files.

This is my vhost config file:

<IfModule mod_ssl.c>


<VirtualHost *:443>
ServerName      www.myweb.com

DocumentRoot    "/var/www/webs/myweb/web"
DirectoryIndex  app.php

<Directory "/var/www/webs/myweb/web">
    AllowOverride None
    Allow from All

    <IfModule mod_rewrite.c>
        Options -MultiViews
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_URI} !^/blog(/.+)? [NC]
        RewriteRule ^(.*)$ app.php [QSA,L]
    </IfModule>
</Directory>

  Alias "/blog/" "/var/www/webs/mywordpress"


  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

  RewriteCond %{HTTPS} off
  RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]


KeepAlive            On
MaxKeepAliveRequests 200
KeepAliveTimeout     5

<IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE "application/atom+xml" \
                                  "application/javascript" \
                                  "application/json" \
                                  "application/rss+xml" \
                                  "application/x-javascript" \
                                  "application/xhtml+xml" \
                                  "application/xml" \
                                  "image/svg+xml" \
                                  "text/css" \
                                  "text/html" \
                                  "text/javascript" \
                                  "text/plain" \
                                  "text/xml"
</IfModule>

<IfModule mod_headers.c>
    Header append Vary User-Agent env=!dont-vary

ExpiresActive On
ExpiresByType image/x-icon "now plus 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/js "access 1 week"
ExpiresByType application/javascript "access 1 week"
</IfModule>
SSLCertificateFile /etc/letsencrypt/live/www.myweb.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.myweb.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

The symfony app is in: var/www/webs/myweb

The Wordpress app is in: var/www/webs/mywordpress

And the wordpress htaccess is:

Options -Indexes
DirectoryIndex index.php

# BEGIN WordPress
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /blog/
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

Any idea of what i'm doing wrong? Thanks a lot.

Upvotes: 1

Views: 447

Answers (2)

KBBx
KBBx

Reputation: 21

Thanks, it worked! After the Alias directive I added this config lines:

<Directory "/var/www/webs/mywordpress">
    DirectoryIndex  index.php
    Options +Indexes
    AllowOverride All
    Allow from All
</Directory>

Upvotes: 1

Moein
Moein

Reputation: 184

Make sure you have the necessary configuration for your wordpress as well.

<Directory "/var/www/webs/mywordpress">
  AllowOverride All
  Allow from All
</Directory>

https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride Reading from here you can see that if you don't specify anything apache won't read anything from .htaccess file Using AllowOverride All tells apache to allow the htaccess to override the apache config If you want to make it more strict then use

<Directory "/var/www/webs/mywordpress">
  AllowOverride FileInfo Indexes
  Allow from All
</Directory>

FileInfo to allow mod_rewrite directive and Indexes to allow DirectoryIndex

Upvotes: 1

Related Questions