开发者

WordPress Symfony Co-habitation

开发者 https://www.devze.com 2023-02-06 15:55 出处:网络
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.

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 contr开发者_JS百科oller
  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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号