WordPress Symfony Co-habitation

本小妞迷上赌 提交于 2019-12-07 10:08:29

问题


We have a site that runs on Symfony and that was developed by people much more competent that myself. I am however quite competent in WordPress and will be installing a blog on a the site.

Currently, the root of the site runs on Symfony but I would like for WordPress to take over without having to touch the Symphony core. Essentially, I would like to install WordPress in a sub directory of the www directory, say www/wordpress/ and have htaccess point to that directory as the root of my domain. BUT, there is one function of my Symfony installation I would like to still have access to, lets call it myfeature. When I go to mydomain.com/myfeature/ I would like for htaccess to point to mydomain.com/index.php/myfeature which is run by Symphony.

Here's what my current .htaccess file looks like.

<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


回答1:


I integrated a wordpress blog with my symfony site using the following.

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

I installe the blog into the main web folder and the .htaccess was set as follows,

RewriteEngine On

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

This allows all of the other routes to be accessed as normal but the blog routes are left untouched and passed directly to wordpress. To pull things from the wordpress database i was able to call the wordpress methods in my symfony controllers and pass it to my twig template.

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

I am not sure if this is exactly what you are asking but it is how my wordpress blog and Symfony 2.0 site co-exist. It is a real pain though I have a wordpress template and a Symfony template that must be kept updated. I really wish I could come up with a better solution to bring these to great tools together.




回答2:


Here you go. I don't think anything below the wordpress controller line will ever be reached, but I left it in anyway

<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>


来源:https://stackoverflow.com/questions/4804182/wordpress-symfony-co-habitation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!