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

ergophobe’s picture

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.

contextcanada’s picture

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.

ergophobe’s picture

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

contextcanada’s picture

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]
#

ergophobe’s picture

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]

contextcanada’s picture

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

ergophobe’s picture

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.

hamzahali’s picture

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

ergophobe’s picture

Thank you! What a kind comment!

mltgroup’s picture

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 $
webfaqtory’s picture

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 :)

rosegirly’s picture

The installation of WordPress might be completely installed but try to check every details from your codes to your sub directory it might be the hindrance of running your blog site. Before, when I have some doubt or question about installer wordpress, I go to the trusted site where I can learn more knowledge about WordPress. Even in formation wordpress, this wordpress training you will realize yourself, your website or your blog and so totally personalized.

Baart’s picture

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

  1. In WP, go to Admin > Settings > Permalinks;
  2. Scroll down to the bottom;
  3. 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.

    <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>
  4. 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]
  5. Paste the WP Admin code underneath this, from "RewriteBase" to the end;
  6. It should work now!
zvischutz’s picture

Thanks , Man
This worked for me perfectly (after 1 hour of htaccess mud fight :( )

gayathrics’s picture

Thank you Baart! Your solution worked!

catalano’s picture

I know this thread is a bit old, but what about doing this with a multi-site instance of Drupal? Where would the WP sub-directory be located and would there be any other required htaccess rules?

Thanks.

mmjvb’s picture

Obviously, the wp folder shouldn't interfere with your drupal site folders. Meaning they have to be named differently.

Consider it bad organization to mix the two and wonder what your business case is.

ergophobe’s picture

I basically agree with you. But the cases I've seen are things like this: someone wants functionality that Drupal provides, but has a thriving blog already and they really like Wordpress. So the regular bloggers can stick with WP and not learn something new and leave Drupal to a more knowledgeable webmaster.

Eight years ago, when I first replied, the use cases were more obvious. Drupal and Wordpress were both much more limited and there were lots of things neither did well (which is why I was running separate gallery software). Nowdays, Wordpress is so much more powerful than it was and so much easier to use and maintain than Drupal (especially D8), that most people should just use Wordpress.

On the other hand, nothing I've seen replaces Drupal's Fields + Views. So if you want structured data and you want to present it in various ways, nothing I know of is close to Drupal. 

But having Drupal and Wordpress for the same site gives you all the complexity of both, all the security issues of both, all the maintenance headaches of both. People should ask themselves if the feature they *must* have from Wordpress or from Drupal is really, truly worth the hassle of maintaining two systems for years to come.

mmjvb’s picture

Objecting to mixing them. There is absolutely no need to mix them. You can still combine them when they are installed separately, each in their own folder. That is what sub domains are for.