4

I have Drupal 7 installed in a ./drupal directory in my web server (shared host).

I would like www.mysite.net to be redirect to www.mysite.net/drupal in a transparent way for visitors. They should see in their navigation bar www.mysite.net instead of www.mysite.net/drupal.

I also want clean URLs to work. To make clean URLs work, I have edited my drupal/.htaccess file and uncomment this line:

RewriteBase /drupal

I read a lot of posts about having Drupal in a subdirectory, but the suggested solutions don't work (they cause an internal server error, or problems with CSS and images). Most of these tutorials are based in 2 htaccess file, one in the root directory and one in the directory where Drupal is installed. They also required to change $base_url in settings.php.

2 Answers 2

2

Try in .htaccess and make sure RewriteEngine On

RewriteRule !^drupal/ drupal/%{REQUEST_URI}

Then try example.com if this maps to example.com/drupal/

I think RewriteBase /drupal will not produce the result.

It should be either RewriteBase / or commented in the case above.


I have gone through this issues deeply and fixed on my end.

Put following rule to your .htaccess on root.

RewriteEngine On
RewriteRule !^drupal/ drupal/index.php?q=%{REQUEST_URI}

The default .htaccess of Drupal is restored to original.

After this setup css and image will fail those are depending on $base_path. I then override $base_path value from /drupal/ to / using hook_init()

function my_custom_module_init(){
   global $base_path;
   $base_path = '/';
}

And this is fixed.

1
  • Thx for your answer, but after adding the rewrite rule on the root htaccess and restore the default htacess in /drupal, I get a error 500 internal server error (no more details are given). I don't understand what is going on.
    – a.b.d
    Commented Jul 4, 2011 at 20:44
2

The following worked for me, but keep in mind that the issue is still in the form of several bugs, that were not yet addressed as of v. 7.14. It involves something with bootstrap.inc, and updated .htaccess between v. 6 and v. 7. I do not fully grasp modRewrite syntax, so particular instructions could be not as efficient. I just used what worked for me (at godaddy.com hosting).

  1. Place Drupal installation in /drupal/ directory (or whichever, adjust accordingly).

  2. Set $base_url in settings.php to your domain ($base_url = 'http://example.net';).

  3. Create .htaccess file in the root directory and place following in it:

    # Don't show directory listings for URLs which map to a directory.
    Options -Indexes
    
    # Follow symbolic links in this directory.
    Options +FollowSymLinks
    
    ReWriteEngine On
    ReWriteBase /
    
    # Exclude other directories from rewrite rules
    RewriteRule ^(exclude1|exclude2) - [L]
    
    RewriteCond %{HTTP_HOST} ^example\.net$ [NC]
    ReWriteRule !^drupal/   - [C]
    ReWriteRule ^(.*)  drupal/$1  [L]
    

    Note: Up to this point, instructions work the same for Drupal 6 (it would be complete now).

  4. In the /drupal/.htaccess file find the section starting with following comments:

    # Pass all requests not referring directly to files in the filesystem to
    # index.php. Clean URLs are handled in drupal_environment_initialize().
    

    Comment out this string (to keep it in case the issue shall be fixed):

    RewriteRule ^ index.php [L]
    

    And add following line (from drupal 6):

    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
1
  • I've been trying to get clean urls to work forever; I think it's step 4 that did it for me. Thanks.
    – gsgx
    Commented Jul 10, 2012 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.