At the suggestion of some here, I have installed the cvs version of Drupal. I have gotten almost everything set up the way I need it (I had to update some modules and create a new one) except for one thing. I can't go live without it. PLEASE help me.

I've set up drupal in a subdirectory but I need the urls to point to the root. I tried the following the instructions and suggestions offered here but I haven't been successful. The following steps are what I thought was supposed to work.

/.htaccess
  # drupal lives in public_html/drupal
      RewriteEngine on
      RewriteBase /drupal
    
includes/conf.php
$base_url = "http://www.mysite.com";
    
Administer >> Settings >> Clean URLs
enabled

My site is currently located at http://www.intraplanar.net/drupal if you want to have a look. I have a lot of existing content and other apps in the root so I can't place drupal there. I also can't start publishing content at /drupal if the url will change in the future.

Support seems to be pretty slow around here (I guess I'm used to the mozilla forums which are much higher traffic) but I hope someone will step up and help me out. Once I get this fixed I hope to contribute a lot to Drupal in the form of patches and modules.

Comments

chx’s picture

You want http://www.intraplanar.net/node/1 to be handled by the http://www.intraplanar.net/drupal installation?

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

If there is a request to www.intraplanar.net which is not a file nor a directory, it will be mapped to the index.php under /drupal.

Most probably you'd need to write a conf_url_rewrite to rewrite outgoing paths. If it is a problem, just let us know. If I misunderstood your wish, the same. While support may be slow, we are here and trying to help.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

tangent’s picture

I wasn't aware of the possibility of using conf_url_rewrite. However, I've looked at it and I don't think that using this method to override the base_url will work. This would change the urls to what I want but the content still needs to be accessible at the new url.

killes@www.drop.org’s picture

I've set up drupal in a subdirectory but I need the urls to point to the root.

Drupal isn't going to work that way. It is quite easy to change the path of a Drupal installation later on. All you need is to change the rewrite base and the base url.

--
If you have troubles with a particular contrib project, please consider to file a support request. Thanks.

tangent’s picture

Drupal isn't going to work that way. It is quite easy to change the path of a Drupal installation later on. All you need is to change the rewrite base and the base url.

Changing URLs is not my concern. I don't want people bookmarking urls (or adding my syndication feeds) in /drupal when I really want them in in the root.

Perhaps what I want isn't achievable with Drupal but I hope it is. I want Drupal to live in /drupal but I want it to appear in and have all urls exist in the root. This seems like such a basic need when you have multiple apps that I would assume I am not the only one.

So far, the /.htaccess changes below make drupal appear from /.

Options -Indexes
Options FollowSymLinks

ErrorDocument 404 drupal/index.php
DirectoryIndex drupal/index.php

<IfModule mod_rewrite.c>
  RewriteEngine off
  RewriteBase /drupal
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /drupal/index.php?q=$1 [L,QSA]
</IfModule>

I also set up my $base_url so that it is dynamic (because I have ssl and want my configuration to handle protocol and path changes).

if ((isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'on')) {
  $base_url = "https://" . $_SERVER['SERVER_NAME'];
} else {
  $base_url = "http://" . $_SERVER['SERVER_NAME'];
}
if ($dir = trim(dirname($_SERVER['PHP_SELF']), '\,/')) {
  $base_url .= "/$dir";
}

Unfortunately, this code still seems to receive "http://www.intraplanar.net/drupal" from the PHP_SELF variable (due to the rewrite?). Hardcoding the value to

$base_url = "http://www.intraplanar.net";

results in the theme not being displayed. "themes/mytheme/style.css" isn't accessible at "http://www.intraplanar.net/themes/mytheme/style.css" even with the Rewrite rules. Do I need another Rewrite rule to handle this?

chx’s picture

RewriteEngine Off? I guess that should be an on... Of course. It's not easy, but I guess

Rewritecond /drupal/%{REQUEST_FILENAME} -f 
RewriteCond /drupal/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /drupal/$1 [L]

Or something like that. If you have a file named /readme.txt and one under /drupal/readme.txt you will be able to reach /drupal/readme.txt

But why are you doing this? Why not just install drupal into /? To my understanding, the original rewrite rule takes care that only those things get rewritten into ?q=drupalpath which does not exist, so existing URLs can be access quite fine.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

tangent’s picture

To answer your question of why I would want to place Drupal in a subdirectory, here is my explanation.

Drupal has 6 subdirectories, as well as at least 3 files in its root. If placed in the root of the web those directories could conflict with other existing directories (scripts, database, these are not exactly uncommon names). Furthermore, to perform an upgrade to a Drupal installation requires replacing the code. It would be much simpler to copy the new code to a new directory (e.g. /drupal-4.6.1) and simply update a symlink to the new code. This provides a fallback if you want to switch back to the previous version. This of course doesn't address db modifications but that's a seperate issue.

tangent’s picture

Yes, the RewriteEngine off was a typo.

Wouldn't your conditions only change urls of form "/drupal/XXX" into "/drupal/XXX"?

Rewritecond /drupal/%{REQUEST_FILENAME} -f
RewriteCond /drupal/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /drupal/$1 [L]

Shouldn't it be this?

Rewritecond /%{REQUEST_FILENAME} -f
RewriteCond /%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /drupal/$1 [L]

I haven't used Rewrite much and I am trying to figure out how to include multiple RewriteRule statements or if this is even necessary. I understand that putting [L] after a rule means it is the last rule, but I don't know if that applies only for the conditions for for all rules.

Do I need something like this or are your rules intended to replace the original rules?

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /drupal

  Rewritecond /%{REQUEST_FILENAME} -f
  RewriteCond /%{REQUEST_FILENAME} -d
  RewriteRule ^(.*)$ /drupal/$1 [L]

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

</IfModule>
chx’s picture

So, once again: would you like that ://yoursite/node/1 be handled by the drupal installation at ://yoursite/drupal? If so, then

a) Everything which is not a file (-f) shall be translated to /drupal/index.php?q=
b) Everything that is called from / but is a file under Drupal, like ./theme which is actually /drupal/theme, it must be rewritten to /drupal/theme.

The only drawback with this trick is that even if you have a real /theme directory, while a) won't apply, but b) would and /drupal/theme would be used, so everything under that directory will become unaccesible.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

tangent’s picture

I have finally achieved what I want. Here is what I currently have. Note the commented RewriteBase statement.

/.htaccess
Options -Indexes
Options FollowSymLinks

ErrorDocument 404 drupal/index.php
DirectoryIndex index.html index.php /drupal/index.php

<IfModule mod_rewrite.c>
  RewriteEngine on
  #RewriteBase /drupal

  RewriteRule modules/(.*)$ drupal/modules/$1
  RewriteRule misc/(.*)$ drupal/misc/$1
  RewriteRule themes/(.*)$ drupal/themes/$1

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

</IfModule>
/drupal/includes/conf.php
# Base URL:
#
#   The URL of your website's main page.  It is not allowed to have
#   a trailing slash; Drupal will add it for you.
#
if ((isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'on')) {
  $base_url = "https://" . $_SERVER['SERVER_NAME'];
} else {
  $base_url = "http://" . $_SERVER['SERVER_NAME'];
}

I'm sure that the RewriteRules could be optimized though and I would welcome suggestions if there are any experts on the subject.

By the way, the style for code elements in this theme needs to be fixed. It doesn't use white-space:pre so isn't quite as attractive.

tangent’s picture

I guess I spoke too soon. URL alias' no longer work. Can anyone debug my RewriteRules so this works again?

Bèr Kessels’s picture

The best opstion for you is to install drupal in the subdirectory, Go live.

When you move your site, you use redirects to point from your old (subdomain) pages to the new (root) pages.

An example of a http redirect is:

#
# Apache/PHP/site settings:
#

Redirect permanent / http://bler.webschuur.com/?q=

you put this in a .htaccess file in your old directory.

This example is placed in my old domainL http://bler.partyfashion.net

Try for example http://bler.partyfashion.net/node/view/140, you will notice you aredirected. And at partyfashion.net there is no drupal installation for that domain at all. In fact, that node (140) has never even existed on the old site :)

That way all things will work properly, most people will be able to use the bookmarks, searchengines will adjust their index when they find that redirect, etcetc.

[Ber | Drupal Services webschuur.com]

tangent’s picture

It shouldn't be that hard to do what I want to do. I've given up and simply dumped everything in the root (which is messy if you want my opinion). I would like to see a code side solution to this problem, instead of the suggested .htaccess hack, which doesn't fully work (without serious Apache expertise perhaps) anyway. Maybe I'll work on it myself.

Bèr Kessels’s picture

Dear tangent.

I have set up about 40 drupal sites already. Only two of which had seriour trouble. Both of them gave me trouble, because the server settings were either very strange (one allowwed only executable php files in root) or way too strict (.htaccess forbidden, php settings ignodred, no Sessions allowed etc).

The .htaccess will work properly, on 90% of the servers. A PHP option will work on less than half of them. So I suggest you complain to your server maintainers and not to drupal developers. .htacces is by far the easiest, cleanest, most powerfull and best performing one. PHP is much, much slower, more complex and less flexible.

[Ber | Drupal Services webschuur.com]

joshuajabbour’s picture

I'm not sure this answers his situation. I don't think anyone ever gave any .htaccess rules that would solve the problem.

I'd have to agree, this is a pretty common situation in most other web apps. As far as I can tell, Drupal expects to be run from the same directory where you access it via the URL. Therefore, if you install in in /drupal, you must access if via htp://www.domain.tld/drupal. You can only access if via htp://www.domain.tld/ if you install it in your web root. Which is less than ideal for many people.

I'd prefer to install Drupal in a subfolder, and have it accessible via my web root, just like the original poster. This is a common occurance for many apps out there, so it would be great if we could build it into the code. Like he said, having a dozen files/folder strewn in my web root is messy, I like to be more organized than that...

tangent’s picture

If the .htaccess solution "will work properly", please give specific .htaccess rewrite rules which allow Drupal to be accessed from a path other than where it is located, and which support clean urls.

here’s picture

see http://drupal.org/node/22336 , I believe this is still not easily achieved.

funkeyrandy’s picture

have site in subfolder: /drupal

want to keep it there!

dont want urls to be:

site.com/drupal/node/xxx

just want everything in place, and browser to remove subfolder from the url:

site.com/node/xxx

can anyone kindly offer specific help on this? would help many im sure.
thanks!

bradrice’s picture

This may not be perfect, but it works for my home page at least. This is my .htaccess. I don't have an index file in my root folder so the rules apply to it.

# Created by web.cgi
Action application/x-httpd-fastphp /fcgi-bin/php5-fcgi
AddType application/x-httpd-fastphp php
# RewriteEngine on
# RedirectMatch ^/$ http://www.bradrice.com/drupal/

Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.bradrice\.com$ [NC]
RewriteRule .* http://www.bradrice.com/ [L,R=301]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]

SecFilterEngine Off

In the case above, I wanted to make sure anyone who had already bookmarked my site with the drupal path still found it.

Now, another source for doing this may be helpful. I was able to pull it off completely with a wordpress blog. Take a look at this and see if it could be replicated for drupal.

http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

In the wordpress case the index.php file is copied to the root folder and the htaccess files are copied. This worked perfectly for me while building a site for an organization. In that case, I just had to append the directory that wordpress lived in to the htaccess RewriteRule. This is what that htaccess looked like.


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I hope this helps,

Brad