.htaccess with wordpress and drupal site

In my root wordpress site running

I have the usual wp-content, wp-includes, wp-admin folders, but I also have my ‘drupal’ which is a drupal site

Read More

I have .htaccess file in both root and drupal directory

When i try to access any node of drupal website give page not found error of wordpress

Please a help me for that

Related posts

Leave a Reply

2 comments

  1. I have seen this a lot with Cpanel and Fantastico.

    https://www.drupal.org/forum/support/post-installation/2010-08-09/installing-wordpress-in-a-sub-directory-of-drupal

    The topic is old but still relevant. Just wanted to share my solution to this problem.

    1. In WP, go to Admin > Settings > Permalinks;

      Scroll down to the
      bottom; You should see this:

    If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press Ctrl+a to select all.
    Add this to WordPress

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

    Open your .htaccess in the Drupal root dir, and find this bit:

    # Pass all requests not referring directly to files in the filesystem to
      # index.php. Clean URLs are handled in drupal_environment_initialize().
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteRule ^ index.php [L]
    

    Paste the WP Admin code underneath this, from “RewriteBase” to the end;
    It should work now!
    Make sure your WordPress permalinks are reset by hitting save ( the first URL here walks you through it
    https://www.cloudways.com/blog/fix-404-error-on-wordpress/

    If that will not work try this.

    See:

    Add this to WordPress

    # 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
    

    Ignoring Subfolders that exist in the DocumentRoot
    With clean URL’s enabled, when running other software applications in subfolders (subdirectories) of a Drupal root installation. your .htaccess file may rewrite those URL’s to Drupal. This may be a particular problem for those with a Drupal installation in the root of their domain using Cpanel and Fantastico where Fantastico installs other software into subfolders. For example, phpSurveyor’s admin interface as installed by Fantastico will not work with Drupal’s default .htaccess settings. The URL for the admin interface is inaccessible and will return a “page not found” page in your Drupal site.

    The trick is to modify .htaccess to ignore specific files/folders. So for example, if you have two folders, and in the root of your Drupal installation, modify your .htaccess file by inserting the following code directly after the “RewriteEngine on” directive, before the Drupal rewrites:

    =========[ start of .htaccess snippet]==========
    <IfModule mod_rewrite.c>
      RewriteEngine on
      #
      # stuff to let through (ignore)
      RewriteCond %{REQUEST_URI} "/folder1/" [OR]
      RewriteCond %{REQUEST_URI} "/folder2/"
      RewriteRule (.*) $1 [L]
      #
    ====================[ end ]=====================
    

    For each folder, you want to bypass, add a RewriteCond line, and end all but the final RewriteCond with [OR]. Note that the [L] in the rewrite rule tells it to stop there and bypass the rest of the rewrite rules.

    Ignoring subfolders that are included via Apache Alias directives
    As of 4.7, files and directories should be automatically allowed through in drupal’s .htaccess setup. Thats what the !-f and !-d lines do.

    However if you are working with Apache Alias or similar directives the file doesn’t actually exist so drupal will take over like it should. The best way around it is to just add one more conditional that matches your location and make it skip it too. Thats what the ! means. Please see below:

    RewriteCond %{REQUEST_URI} !^/yourDirectoryName
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    It essentially means Apply this rule if the REQUEST_URI doesn’t start with /yourDirectoryName and the REQUEST_FILENAME isn’t a real file or a real folder. Which is exactly what you want. There is an implied “AND” between the lines of that rule. The ! says “not like this”.