Goal: make "www.mysite.com/subdirectory" appear as just "www.mysite.com" to the browser

I've been following the guidelines in several discussion threads concerning how to make modifications to one's .htaccess file for 3 days now. I'm feeling totally pathetic and asking for fellow godaddy hosted drupal users with their sites in subdirectories how they managed to get it to work...

Discussions I've read and tried to implement without success and just added confusion:
http://drupal.org/node/144643
http://drupal.org/node/135206
http://drupal.org/node/89089
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html#introduction
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html

However, most of these don't really explain how these modifications work, nor what they are doing beyond the author's assurance that they worked for them... Note that following the instructions and variations of them in the first three links above, I get the site redirecting with the subdirectory hidden in the browser, and the site works, but with no theme at all, and firebug errors saying that various files are not being found...

So, please, please, if you understand how mod_rewrite works, could you answer any of the following:

Drupal comes with an .htaccess file...

  1. when placing drupal in a subdirectory of docroot, I believe I need to have a .htaccess file at docroot as well as inside the drupal root, correct?
  2. It seems to me that I could just handle all rewriting with the .htaccess at docroot, correct?
  3. The default .htaccess file comes with the following rewriteRules already active:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    That last line, the RewriteRule itself has [L,QSA] flags specified:

  4. the 'L' flag says that this is the last rule, so any additional rules added afterwards will be ignored, right?
  5. the 'QSA' flag is for appending a query string to the rewritten URI, but isn't the replacement string given already doing that?
  6. as I began to understand more about these rewrite rules, I thought changing that last one to this would do the trick, but did not:
    RewriteRule ^(.*)$ drupal_6_13/index.php?q=$1 [L,QSA]
    

    and of course, I deactivated the .htaccess file inside the drupal root via renaming it, and I left the sites/default/settings.php file alone, since that above rewriteRule should be doing everything necessary... but that did not work...

Any knowledgeable gurus wanna take pitty on my sorry ass and explain some of this voodoo?

-Blake

Comments

amaudy’s picture

how about value of "RewriteBase"?

eg.

RewriteBase /

RewriteBase /subdirectory

did you try some thing like this?

bsenftner’s picture

I'll try them again. Just a few hours ago I was trying the "RewriteBase /" version without success... I'm still unclear on the significance of the .htaccess inside drupal root (subdirectory of docroot) and the .htacess inside docroot. It seems like the issue is not being completely framed when people reference the situation. There are three factors, as far as I know, of files that could be modified to fix this:

  1. .htaccess inside docroot
  2. .htaccess inside drupal root
  3. sites/default/settings.php

and it looks like I need to step through variations of advice to find my solution.

bsenftner’s picture

I seem to have the mod_rewrite stuff working, but drupal (I think) is generating links with the subdirectory in it, so the subdirectory is still visible in the browser window.

I can go to "www.mysite.com" and it loads correctly, hiding the redirection to the subdirectory.
I can enter "www.mysite.com/subdirectory" and it loads the same, but now shows the subdirectory in the browser address bar... I can live with that...
However, if I click any links in the site, drupal (I think) generates a url with the subdirectory in it, so they appear in the address bar.
Yet, I can take that same address, and just remove the subdirectory portion, and it loads the correct page. Nice.

But if I go to the sites/default/settings.php and set:
$base_url = 'http://www.mysite.com';
I get the site working, but no theme at all... so I tried:
$base_url = 'http://www.mysite.com/subdirectory';
and I get the site again, but all the links are showing the subdirectory, same thing as if that line were commented out.

So I currently have the following (very close but not yet right) setup:

Inside docroot's .htaccess file is:

  RewriteEngine on
  # RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule (.*) drupal_6_13/$i [L]
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

(and I suspect that 2nd RewriteRule is ignored, since the 1st one has that "L" flag, but not really sure...

Inside drupal root (subdirectory of docroot):

  RewriteEngine on
  # RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

and sites/default/settings.php is unchanged (the $base_url modification is commented out)
and I've removed any index.php and index.html from docroot... they both held html redirects like
header( 'Location: http://www.site.com/drupal_6_13/' ) ;
and I suspect were also having input and throwing me off solutions...

This is sooo close!

bsenftner’s picture

Found a possible bug in my docroot's .htaccess. but the behavior has not changed...

In the above docroot .htaccess, my second to the last line is:

RewriteRule (.*) drupal_6_13/$i [L]

However, the use of "$i" is meaningless (I think), so I've changed it to:

RewriteRule (.*) drupal_6_13/$1 [L]

Yet the behavior of the site is the same:

I can go to anyplace in the site as:
"www.mysite.com/[drupal query string]",
but the links in the site generate:
"www.mysite.com/subdirectory/[drupal query string]"

bsenftner’s picture

I believe that bug in my docroot's .htaccess may have been causing a large portion of my grief...

For others facing this same challenge, here's the final working solution:

Inside docroot's .htaccess file, the mod_rewrite section:

  RewriteEngine on
  # RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule (.*) drupal_6_13/$1 [L]
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

and I still don't know if that 2nd RewriteRule ever gets used, because of the "L" flag in the first RewriteRule. Anyone?

Inside drupal's root is another .htaccess file, and that mod_rewrite section has:

  RewriteEngine on
  # RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

this is the unchanged default .htaccess that comes with drupal.

Inside sites/default/settings.php:

  $base_url = 'http://www.mysite.com';  // NO trailing slash!

Hopefully this will save someone else from my grief.

I'd also like to thank the following drupal.org members for their kind and supportive help:
amaudy, pulsifier, udijw, CheckeredFlag, and of course the drupal developers and documentation team.

This community rocks!

tingtong’s picture

I follow this method and is ok. Any problem in future if I want to upgrade to Drupal 7?

bsenftner’s picture

I don't know. Drupal 7 will probably function in much the same way, but I have not tried it on any remote hosted sites yet - just locally, to test drive it.

slash75’s picture

I have a drupal site setup on godaddy at http:///www.mysite.com/drupal

I want to redirect to http:///www.mysite.com

I tried everything above but it didn't work.

bsenftner’s picture

I've found the GoDaddy setup to be rather fragile, and really slow... so I've moved most everything to HostGator. :( Sorry.

waynedpj’s picture

thanks so much to original poster bsenftner for this solution. i have also spent days trying to solve this same problem with Apache 2.2 & Drupal 7 on a local server. unfortunately, the changes as recommended to not quite work: the root URL will forward to the Drupal subdirectory correctly, but the site does not function: clicking on links after logging in result in a quick shadow as some JS overlay is happening, but then fails and simply returns to the front page. removing the RewriteRules allows the site to work again.

i will continue to research this and update this comment if i find a solution.

thanks.

connellc’s picture

This was really freaking disappointing not seeing a solution so far. I feel like Charlie the Tuna, to be so close and have the solution just "yanked!" away.

A lot of us have clients. We don't pick the server. The clients do. My client likes the GoDaddy email & Calendar; she doesn't want to to go to any
new server. She likes things just the way they are!

So I don't have a choice, such as to move my files somewhere else; it's not an option!

My D7 is working fine. All I want is to remove the drupal folder in the URL: www.somesite.com/drupal/.

A little help would be nice.

So it's D7, GoDaddy - help me find a way! Please?

connellc’s picture

Go to this thread: http://drupal.org/node/144643

I'm happy - does exactly as advertised! :-)

arsisthesis’s picture

Thank you Blake, your solution in http://drupal.org/node/520700#comment-1819902 works perfectly for me.
However, I would like to point out one nuance for friends using Drupal 7.10:
In the default mod_rewrite section of Drupal 7.10 folder's .htaccess, the last line becomes: RewriteRule ^ index.php [L]
So if we leave the default setting unchanged, the solution will not work.
I had to change the default setting to your version which should be the Drupal 6.13 default setting : RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Best regards,
Arsis

montag64’s picture

I've tried Blake's solution and it seems to work as far as navigation goes (example.com/hiddendir/blah takes me to example.com/blah) but any links on the page that I nav to add back the /hiddendir/ in the address bar. So the hiddendir isn't hidden. 

I think the root of the issue seems to be that $base_url is ignored and does nothing in Drupal 8 when you put it in your settings.php file. Apparently it was removed for security reasons.

Does anyone have a solution for this in 2019 with Drupal 8? The only information I can find on this is for Drupal 7 or several year old info. 

empowerment’s picture

Took me a long time to realize that A2's VPS is automatically configured to use lighttpd instead of apache, because the landing page is an Apache test page. In case anyone's dealing with this issue, you can change over to Apache in kloxo by going to "Switch Programs" in the "Server::Linux" section!

js_kiran’s picture

More than 3 1/2 years after you posted, this solved my problem. I have spent an entire Sunday trouble shooting this and found this post just before calling quits. Why can't Godaddy have this tutorial on this knowledge base instead.

Thanks a million for this post

diggydiggy’s picture

Hi, I have followed the instructions above, and like many others, have read 20 other articles of no value.

The redirect to the main root works but accessing any other link readds the subdirectory to the link and produces a 404. I followed the instructions exactly as provided, there is good reason why Drupal suffers.. lots of smart ppl here who do not spend the time to write proper instruction! Help anyone?

mollyavalon’s picture

I've been struggling with this too. I'm using D7. I could get most of it to work, except that I kept getting Not Found on the inner pages.

The comment at https://drupal.org/node/520700#comment-7213786 was the solution.

The total setup for me was

  1. edit the root .htaccess as noted here: https://drupal.org/node/520700#comment-1819902
  2. edit the drupal .htaccess in two ways:
  3. edit the settings.php file. Do NOT include the subfolder where Drupal resides: $base_url = 'http://mysite.com'; // NO trailing slash!

Many many thanks to everyone who chimed in!

Marc Angles’s picture

Here is what I have and works in a subdirectory of the webroot at godaddy :

The .htaccess in the webroot (what we find at https://www.drupal.org/node/520700#comment-1819902)

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule (.*) DIR_NAME/$1 [L]                                  #   <--- Replace the DIR_NAME with yours
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

The .htaccess inside the drupal directory

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

Thanks @ all for this.

m.attar’s picture

Thanks all it works well!!!!

masifi’s picture

Many thanks Mr.Marc it worked for me.