Wordpress inside Cakephp

2019-02-11 07:20发布

问题:

I have installed Wordpress inside Cakephp's /app/webroot/blog/ folder and changed the wordpress permalink settings to Month and name (eg. http://abc.com/blog/2013/02/sample-post/).

Now when i am viewing a post i am getting Missing Controller(Error: BlogController could not be found).

I want to change the cakephp routes so that anything with /blog/* will point to webroot blog folder.

Can anybody help me on this?

回答1:

When we change the permalink settings of Wordpress, it generates a .htaccess file, if there is required permission else we have to create it.

In the above case there was no .htaccess file inside /blog/ folder. I created it with the following mod_rewrite rules as provided by Wordpress while changing permalink settings.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /blog/
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /blog/index.php [L]
</IfModule>

After this every thing works fine.



回答2:

There is no need to put the blog folder in webroot folder. You can access your folder by making slight changes in your .htaccess file. Just put your wordpress folder on root of cakephp with app folder and change .htaccess as given below.

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule (blog/.*) $1 [L] # adjust the regex to what you want.
    RewriteRule    ^$ app/webroot/    [L]
    RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>


回答3:

I tried both the above codes but none work for me.. then i found something by my own and it worked..So here it is ,, hope this will help some.

First Add the WordPress folder inside the webroot folder as blog. Inside blog paste the WordPress directories and files.. install the WordPress.. Now you will see in the WordPress admin general settings WordPress Address as http://cakephp/blog/app/webroot/blog, Change it to http://cakephp/blog. Save it ..

Now look for the .htaccess file in WordPress install root folder change RewriteBase and RewriteRule (last one ) to RewriteBase /blog/ and RewriteRule . /blog/index.php [L]

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /blog/
 RewriteRule ^index\.php$ – [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /blog/index.php [L]
</IfModule>