【问题标题】:WordPress Symfony Co-habitationWordPress Symfony 同居
【发布时间】:2011-06-15 19:22:16
【问题描述】:

我们有一个在 Symfony 上运行的网站,它是由比我更有能力的人开发的。然而,我在 WordPress 方面非常称职,并将在网站上安装博客。

目前,站点的根目录在 Symfony 上运行,但我希望 WordPress 接管而无需触及 Symphony 核心。本质上,我想将 WordPress 安装在 www 目录的子目录中,例如 www/wordpress/ 并将 htaccess 指向该目录作为我域的根目录。但是,我还想使用 Symfony 安装的一个功能,我们称之为myfeature。当我转到 mydomain.com/myfeature/ 时,我希望 htaccess 指向由 Symphony 运行的 mydomain.com/index.php/myfeature

这是我当前的 .htaccess 文件的样子。

<IfModule mod_rewrite.c>
  RewriteEngine On

  # we skip all files with .something
  RewriteCond %{REQUEST_URI} \..+$
  RewriteCond %{REQUEST_URI} !\.html$
  RewriteCond %{REQUEST_URI} !\.php
  #RewriteCond %{REQUEST_URI} !\.php
  RewriteRule .* - [L]

  # we check if the .html version is here (caching)
  RewriteRule ^$ /index.html [QSA]
  RewriteRule ^([^.]+)$ /$1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ /index.php [QSA,L]

  # hidden frontoffice controller
  RewriteRule ^index\.php/(.*)$ /index.php [QSA,L]
  # fo controllers
  RewriteRule ^frontend\.php/(.*)$ /frontend.php [QSA,L]
  RewriteRule ^frontend_dev\.php/(.*)$ /frontend_dev.php [QSA,L]
</IfModule>

谢谢

【问题讨论】:

  • Symfony 通常为 Apache VirtualHost 设置中的供应商 Web 内容定义至少一个 Alias -- 请参阅Web Server Configuration on this page -- 您的站点是这样设置的吗?如果是这样,您是否可以在该级别为 WordPress 添加一个类似的别名?可能会让您不必混合和匹配 Symfony 和 WordPress .htaccess 规则。

标签: wordpress mod-rewrite symfony1


【解决方案1】:

给你。我认为不会达到 wordpress 控制器线以下的任何内容,但无论如何我还是保留了它

<IfModule mod_rewrite.c>
RewriteEngine On

# we skip all files with .something
RewriteCond %{REQUEST_URI} ..+$
RewriteCond %{REQUEST_URI} !.html$
RewriteCond %{REQUEST_URI} !.php
#RewriteCond %{REQUEST_URI} !.php
RewriteRule .* - [L]

# we check if the .html version is here (caching). If yes, don't redirect
RewriteRule ^$ /index.html [QSA]
RewriteRule ^([^.]+)$ /$1.html [QSA]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

# if the 'myfeature' prefix is there, redirect to Symfony controller
RewriteCond %{REQUEST_URI} ^/myfeature/
RewriteRule .* index.php [QSA,L]

# otherwise, redirect to wordpress controller
RewriteRule .* wordpress/index.php [QSA,L]

# hidden frontoffice controller
RewriteRule ^index.php/(.*)$ /index.php [QSA,L]
# fo controllers
RewriteRule ^frontend.php/(.*)$ /frontend.php [QSA,L]
RewriteRule ^frontend_dev.php/(.*)$ /frontend_dev.php [QSA,L]
</IfModule>

【讨论】:

    【解决方案2】:

    我使用以下方法将 wordpress 博客与我的 symfony 网站集成。

    //Added to the autoload.php
    require('../vendor/wordpress/wp-blog-header.php');
    

    我将博客安装到主网络文件夹中,.htaccess 设置如下,

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !/blog -------Add this condition to by pass the rewrite rules
    RewriteRule ^(.*)$ app.php [QSA,L]
    

    这允许所有其他路由正常访问,但博客路由保持不变并直接传递给 wordpress。为了从 wordpress 数据库中提取内容,我可以在我的 symfony 控制器中调用 wordpress 方法并将其传递给我的 twig 模板。

    $posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
    return array('posts'=>$posts);
    

    我不确定这是否正是您要问的,但这就是我的 wordpress 博客和 Symfony 2.0 网站共存的方式。虽然我有一个 wordpress 模板和一个必须保持更新的 Symfony 模板,但这真的很痛苦。我真的希望我能想出一个更好的解决方案,将这些工具整合到一起。

    【讨论】:

      猜你喜欢
      • 2011-07-18
      • 2017-10-06
      • 1970-01-01
      • 2011-10-10
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 2013-01-10
      • 2012-03-15
      相关资源
      最近更新 更多