我们有一个在 Symfony 上运行的网站,它是由比我更有能力的人开发的。不过,我对 WordPress 非常熟悉,并将在该网站上安装一个博客。
目前,该网站的根运行在 Symfony 上,但我希望 WordPress 能够接管,而不必触及 Symfony 核心。本质上,我想将 WordPress 安装在 www 目录的子目录中,例如www/wordpress/
并使 htaccess 指向该目录作为我的域的根目录。但是,我的 Symfony 安装有一个功能我仍然想访问,我们称之为它myfeature
。当我去mydomain.com/myfeature/
我想让 htaccess 指向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>
谢谢
我使用以下命令将 WordPress 博客与我的 symfony 网站集成。
//Added to the autoload.php
require('../vendor/wordpress/wp-blog-header.php');
我将博客安装到主 Web 文件夹中,并且 .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 模板必须保持更新,但这确实很痛苦。我真的希望我能想出一个更好的解决方案,将这些功能整合到优秀的工具中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)