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

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?