Community & Support

Installing Wordpress in a sub directory of Drupal

We are working with example.ca to launch a WordPress blog. We have tried to install it in a sub-directory of the url example.ca which is in Drupal, called example.ca/blog but we are having issues with images and embedded links that do work or display. The install was done through cpanel and Fantastico. I have searched for answers to this and it might be something to do with index.php and .htaccess files that are part of the root directory? Can this be fixed or do we need to move the blog into a sub domain?

Comments

You need to make sure your

You need to make sure your rewrites for Drupal specifically exclude the /blog/* path, then it should all work fine.

But it begs the question of why you don't simply turn on the blog module in Drupal.

Don't get me wrong, I use Wordpress when all I want is blog. But if I'm going to install Drupal anyway, I would just use the Drupal blog function.

I do think that Wordpress is easier for most people to get their heads around and that may be an issue for you depending on who will do the actual blogging, but Drupal can be set up for a user with limited permissions that will present few choices. You can add in the Dashboard module and have something pretty close to WordPress without having to maintain two packages.

Yosemite Explorer - hiking and climbing in Yosemite (drupal)

Rewrites

You need to make sure your rewrites for Drupal specifically exclude the /blog/* path, then it should all work fine.
Can you provide me with more detail on your suggestion?
As to the reasons, they are exactly as you mentioned, easier for the client to use and less involvement for me.

In your .htaccess for Drupal

In your .htaccess for Drupal where it's checking for files and directories, you need to add another rewrite condition like

RewriteCond %{REQUEST_URI} !^blog

That means that Drupal won't try to rewrite your /blog* URLs and let them pass on to WordPress

Yosemite Explorer - hiking and climbing in Yosemite (drupal)

your code was a little off

your code was a little off (didn't work so Iused the following).
=========[ start of .htaccess snippet]==========

RewriteEngine on
#
# stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/folder1/" [OR]
RewriteCond %{REQUEST_URI} "/folder2/"
RewriteRule (.*) $1 [L]
#
====================[ end ]=====================
Got this from node 30334 in the forums.
I added this to my .htaccess file, but it didn't solve anything! Any thoughts on this. Hope the view and weather are nice there.

RewriteEngine on
#
# stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/blog/" [OR]
RewriteCond %{REQUEST_URI} "/blog/"
RewriteRule (.*) $1 [L]
#

Well, since my code is in

Well, since my code is in actual use, to run Gallery within a Drupal install...

It is not *complete* - it needs to be integrated with your other rewrite conditions and rules.

My code says this:
If the request URI does NOT begin with "blog" then....

And the rest of your code needs to give the other conditions such as the standard Drupal file and directory checks (the -f, -d conditions in the drupal default .htaccess) and then the drupal rewrite rule.

In that case it says
If the request URI does NOT (!) BEGIN (^) with "blog" and the requested URI does not map to a file or directory, then rewrite to invoke drupal.

Put another way
If the request URI is for my blog or a file or a directory, serve that straight up, without handing me off to drupal. So in the case of your blog, it passes you through to WP

Your code says this
If the Request URL is "/blog/" or "/blog/" then take that URL and rewrite it to be the same as it was before and quit.

In any case, you don't need quotes if there's no whitespace.

As for the leading slash - run the HTTP Live Headers plugin in Firefox to see what the server thinks your actual REQUEST_URI is (or use phpinfo() on your /blog directory). In my case at least, it does not want the leading slash.

So depending on what else you have, it might look like this

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_URI} !^blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Yosemite Explorer - hiking and climbing in Yosemite (drupal)

Took the easier route

I bailed out, because I do not understand the "code" well enough to fix the problem. So I installed the "blog" as a sub domain and it seems to work, so far. I really appreciate your taking the time to respond. I would definitely like to try your solution at some point. If you are interested I could provide you with the htaccess file and you can see what I have done so far?
I may need further assistance with it and would like to stay in contact. It would seem that you are the only source I can find that appreciates how this could actually work.
Many thanks for your input.
Terry

All you need is the code at

All you need is the code at the end of my last post. Try putting *just* that in your .htaccess. It should work.

If it doesn't, look at your server logs - access and error - and your Drupal Watchdog logs. Those will tell you what's going wrong and how to adjust your rewrites.

The main thing is to read the mod_rewrite manual. It's a bit of geek speak, and understanding regular expressions is helpful, but if you plan to be running sites long term, trust me, learning some basics of regular expressions and mod_rewrite is going to add years to your life. Okay, maybe not, but it's a powerful toolkit and worth learning.

Yosemite Explorer - hiking and climbing in Yosemite (drupal)

Apprication

Just want to appricate you for your intense desire to help others. God bless you.

Thank you! What a kind

Thank you! What a kind comment!

Yosemite Explorer - hiking and climbing in Yosemite (drupal)

cannot get drupal to see my subdirectory

Hello,

I am having the same issue as the other writer. I am trying to install wordpress under a blog folder and no matter where I put the rewriteCond above it doesn't serve up the page correctly.

Below is my htaccess code:

thanks

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
  php_value max_execution_time 0
  php_value memory_limit 156M
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
  php_value max_execution_time 0
  php_value memory_limit 156M
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
  php_value max_execution_time 0
  php_value memory_limit 156M
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  # Do not cache dynamically generated pages.
  ExpiresByType text/html A1
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
   RewriteCond %{HTTP_HOST} ^www\.domailleengineering\.com$ [NC]
   RewriteRule ^(.*)$ http://domailleengineering.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_URI} !^blog
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

# $Id: .htaccess,v 1.90.2.3 2008/12/10 20:04:08 goba Exp $

You also need to add a .htaccess

You also need to add a .htaccess file to your wordpress sub-directory

This worked for me. The mod_rewrite section of the .htaccess file in the root Drupal directory looks like below:

<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_URI} !^blog
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

And I then copied a unmodified Drupal .htaccess file into the wordpress sub-directory and it all worked :)

nobody click here