dongza1708 2016-10-06 11:55
浏览 79
已采纳

WordPress作为Symfony(Symfony3)子目录

I am running a Symfony app on DigitalOcean. I have setup the entire site and created VirtualHosts. I need to run WordPress as a subdirectory (/blog). From what I know Symfony tends to ignore subdirectories in /web so I created /web/blog and installed WordPress in it.

<VirtualHost *:80>
    DocumentRoot /var/www/html/site.com/web
    <Directory /var/www/html/site.com/web>
        AllowOverride None
        Order Allow,Deny
        Allow from All

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

    ErrorLog /var/log/apache2/symfony_error.log
    CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>

On localhost installations without VirtualHost this runs perfectly.

But on the live server, lets say at 21.21.21.21 I have Symfony running and 21.21.21.21/blog should open blog but it doesn't, instead goes to a Symfony 404. Whereas 21.21.21.21/blog/index.php runs the blog (WordPress).

The WordPress .htaccess which lives in /web/blog is as follows:

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

I have tried tinkering with this with some answers on the web, nothing changes.

  • 写回答

1条回答 默认 最新

  • dongtan5558 2016-10-06 17:17
    关注

    Update your vhost so that you exclude your /blog directory from symphony rules. And you will also need to change to AllowOverride All since you are using .htaccess in /blog.

    <VirtualHost *:80>
        DocumentRoot /var/www/html/site.com/web
        <Directory /var/www/html/site.com/web>
            AllowOverride All
            Order Allow,Deny
            Allow from All
    
            <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteCond %{REQUEST_URI} !^/blog(/.+)? [NC]
                RewriteRule ^(.*)$ app.php [QSA,L]
            </IfModule>
        </Directory>
    
        ErrorLog /var/log/apache2/symfony_error.log
        CustomLog /var/log/apache2/symfony_access.log combined
    </VirtualHost>
    

    Be sure to restart apache after changes.

    WordPress .htaccess Changes:

     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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀