I have drupal installed as the root of my main domain. But I have now added some subdomain/add-on domains to that account (which do not use the main domain name), and the drupal mods to the .htaccess file makes these subdomains unusable. I have confirmed this by removing the .htaccess file and it works as expected.

I realise that with some tweaking I could probably get these sites to work in harmony, but I dont want to have to edit the .htaccess for each new add-on domain... but I would still like to know how to do it for the interim. Somehow work out what lines are drupal specific and tell them to ignore my add-on domains, or some other way... HELP

What I would really like to do is clean up the root of my public_html folder by shipping my drupal installation to a subdirectory or subdomain of it (either/or).

I know it is not as simple as moving the files from the root of public to a sub folder, what other edits would be needed? ie, obviously some edits to the .htaccess files, but what about db settings? I'm sure from my Drupal 4 days there is a reference to the location in there somewhere 9but that was so long ago)...

Any help appreciated...

Not sure if anyone wants to see this, or needs to, but here is my .htaccess file:

AddHandler application/x-httpd-php5 .php
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
# Customized error messages.
ErrorDocument 404 /index.php
# 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>
</IfModule>
# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
</IfModule>
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
</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/...)
# adapt and uncomment 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 and
# the rewrite rules are not working properly.
#RewriteBase /drupal
# Rewrite old-style URLs of the form 'node.php?id=x'.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{QUERY_STRING} ^id=([^&]+)$
#RewriteRule node.php index.php?q=node/view/%1 [L]
# Rewrite old-style URLs of the form 'module.php?mod=x'.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
#RewriteRule module.php index.php?q=%1 [L]
# Rewrite current-style URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
# $Id: .htaccess,v 1.81.2.3 2007/09/21 12:24:22 drumm Exp $

Comments

madivad’s picture

I was just thinking, in the admin settings, there is a provision for where files will be located, ie the 'files' directory... I would have to change this to "subdomain/files" wouldn't I? or is that relative to where the subdomain resides?

vm’s picture

It actually is as simple as moving the files from where they are into a subdomain folder.

after that clear your cache tables in the DB
if using a base url in settings.php insure to change it to reflect new location.

Drupal is very modular and is relative to its own index.php file

madivad’s picture

it really was that simple!!! I moved the entire lot into a subfolder, including the htaccess file, I created a new htaccess file to point my existing domain to the subfolder, but having it remain the domain name (ie no apparent subdomain or folder).

old: dav3.net -> public_html
new: dav3.net -> public_html/subdir

So then I created a nice shiny new htaccess file that sends anyone coming into my domain to the new subdir

In case someone else may find this useful, my new .htacess file:

# Do not change this line.

RewriteEngine on


# Change yourdomain.com to be your main domain.

RewriteCond %{HTTP_HOST} ^(www.)?dav3.net$


# Change 'subfolder' to be the folder you will use for your main domain.

RewriteCond %{REQUEST_URI} !^/mynewsubdomain/

# Don't change this line.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change 'subfolder' to be the folder you will use for your main domain.

RewriteRule ^(.*)$ /mynewsubdomain/$1

# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.

RewriteCond %{HTTP_HOST} ^(www.)?dav3.net$
RewriteRule ^(/)?$ mynewsubdomain/index.php [L]

Since everything flows from the index.php location, then all worked well...

Also, because the base url was to remain unchanged, I did not need to change the settings.php file

Thanks Mr Misunderstood :-)

techguy10’s picture

I'm trying to do the same thing.. I moved my files to the new directory but I'm having trouble with the "clear the DB cache tables" part. Is this something that is done from within Drupal or directly with mysql, I'm using a 3rd party host and I don't see any options to do this in their cpanel.

jscoble’s picture

directly within mysql

I would also clear the session table

dwongu’s picture

So, I cleared the cache tables, but I can't find a "session" or "sessions" table. Any ideas?

Thanks!

vm’s picture

can't explain why you don't have a sessions table. It's a necessary table to hold the login's when they occur. It should be there. If it isn't then you've an issue with your DB. ie: perhaps you dropped the table at some point?

harvlad’s picture

worked for me, thanks

benmiller314’s picture

Thanks so much for this -- I didn't know better than to install in root, so advice elsewhere to just start over with a clean install was really unhelpful.

For the record, I had to add a Query String Append flag (see http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa) to the RewriteRule in line 11 for my site to work properly. That is, instead of these lines:

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /mynewsubdomain/$1

I used something like this:

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /mynewsubdomain/$1 [QSA]

Only then did sub-pages pass through to the proper page (all with the URLs properly masked to look like they were in the root directory). Hope that helps someone out there!

Isaacheng’s picture

Hi Mavidad,

my Drupal site is on a subdirectory because i am currently trying out. Later on when it is ready i will move it to root, which is the reverse of the issue you raise.

may i ask how will you activate your website? i mean people will type in www.abc.com and not www.abc.com/drupal/

(sorry if this is a no-brainer but it was only two weeks ago that i stare at the screen and wondered what ftp stands for, the 'f' i know but 'tp'?)

vm’s picture

ftp = file transfer protocol

webopedia.com/TERM/F/FTP.html

jordanyerman’s picture

I had a similar issue when moving my Drupal installation from http://internationaljettrash.com to http://vintage.internationaljettrash.com

After the move, I was unable to login, and all pages besides the landing page were 404. I manually inserted ?q= to create /?q=login, and was able to produce the login screen; I could login successfully. Dirty URLs!

After that, I manually entered http://vintage.internationaljettrash.com/?q=admin/settings/clean-urls and disabled cleanurls.
Then I was able to navigate the site like a normal human being; the next steps were to clear cache tables and re-enable cleanurls.

This solved the problem.