WordPress和Symfony共存

4
我们有一个运行在Symfony上的网站,是由比我更有能力的人开发的。然而,我在WordPress方面相当熟练,并将在该网站上安装一个博客。
目前,网站的根目录运行在Symfony上,但我希望WordPress接管而不必触及Symfony核心。本质上,我想在www目录的子目录下安装WordPress,比如说www/wordpress/,并让htaccess将其指向作为我的域名根目录。但是,我仍然希望使用Symfony安装的一个功能,我们称之为myfeature。当我访问mydomain.com/myfeature/时,我希望htaccess将其指向运行于Symfony的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>

Thank You


Symfony通常在Apache的VirtualHost设置中为供应商Web内容定义至少一个“别名” - 请参见此页面上的Web服务器配置 - 您的网站是否设置了这样的别名?如果是,您是否可以在该级别添加类似的别名以用于WordPress?这可能会节省您混合和匹配Symfony和WordPress .htaccess规则的麻烦。 - Matt Gibson
2个回答

2

给你。我不认为在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
我使用以下方法将我的Symfony站点与WordPress博客集成。
//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模板,必须保持更新,它真的很麻烦。我真的希望能够想出更好的解决方案来将这两个强大的工具结合起来。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接