Search code examples
wordpress.htaccessurlcakephpsubdirectory

.htaccess rules to have wordpress in root and cakephp in subfolder


i installed wordpress in the root directory of my FTP, and then in a subfolder I install cakephp, however I have a problem with htaccess.

www/
.htacess
(wordpress)
/folderCakephp/
              .htacess
              (cakephp)

Wordpress htaccess :

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

Cakephp root htaccess :

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Cakephp app/ htaccess :

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

Cakephp app/webroot/ htaccess :

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

the problem is that when I go on www.domain.com/folderCakephp/ I have a Wordpress 404


Solution

  • In the directory where WordPress is installed, i editing the .htaccess file and i have add the following line. (CakePHP subdirectory will be called "cake")

    Wordpress .htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
     RewriteRule ^cake/(.*)$ /cake/$1 [L,QSA]
     RewriteRule ^index\.php$ - [L]
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    /cake .htaccess

    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteBase /cake
     RewriteRule ^$ app/webroot/ [L]
     RewriteRule (.*) app/webroot/$1 [L]
    </IfModule>
    

    /app .htaccess

    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteBase /cake
     RewriteRule ^$ webroot/ [L]
     RewriteRule (.*) webroot/$1 [L]
    </IfModule>
    

    /app/webroot .htaccess

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /cake
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
    

    That’s it. You’re good to go.

    Visiting example.com in the browser will open your WordPress website, while example.com/cake/, depending on how you configured it, will open your CakePHP app.