使用Symfony app的Wordpress博客 - Apache Alias config

时间:2017-10-02 19:37:24

标签: wordpress apache symfony

我有一个Symfony应用程序,我想在子目录/博客上运行Wordpress。 Wordpress安装位于其自己的目录中,而不是在Symfony的Web文件夹中。

问题是Wordpress没有执行index.php文件,当我访问myweb.com/blog时,我会看到“Index Of”页面,其中包含所有wordpress文件夹文件的列表。

这是我的vhost配置文件:

<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>

symfony app位于:var / www / webs / myweb

Wordpress应用程序位于:var / www / webs / mywordpress

wordpress htaccess是:

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

知道我做错了什么吗?非常感谢。

2 个答案:

答案 0 :(得分:0)

确保您的wordpress也具有必要的配置。

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

https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride 从这里读取你可以看到,如果你没有指定任何东西,apache将不会读取.htaccess文件中的任何内容 使用AllowOverride All告诉apache允许htaccess覆盖apache配置 如果你想让它更严格,那么使用

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

FileInfo允许mod_rewrite指令和索引允许DirectoryIndex

答案 1 :(得分:0)

谢谢,它有效!在Alias指令之后我添加了这个配置行:

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