views:

23

answers:

2

I am trying to redirect all requests to domain.com/drupal to domain.com, including all sub directories in /drupal.

I have seen several answers telling me how to accomplish the opposite of this with .htaccess, but nothing to go this way. I have tried the following line in .htaccess-

RewriteRule /drupal/* ^/(.*)

as well as several variations of the above, based on those answers, but haven't had any luck.

Thanks!

A: 

Try this line:

RewriteRule /drupal/(.*) /$1 [QSA,L]
Paul
Thanks, I was able to use the Redirect Manager my webhost provides to configure it (I had tried that and it wasn't working, but then I found some additional help with it). THe code you have provided looks like what I was looking for, so while I can't test it, I'm going to vote for it. (I'll try it out the next time I need to do this :)
ensignavenger
A: 

Let me get this straight ... You have an installation of Drupal in <DocumentRoot>/drupal/. You do not want to alter the drupal installation directory, nor you want to change DocumentRoot in your webserver config. You want to redirect any request, for example /foobar.php, into the drupal directory, resulting in maybe /drupal/foobar.php. And all that without exposing the whole stuff to the user. Right so far? OK, I can only assume that you have an Apache webserver, else .htaccess would not work...

First, make sure that you actually are allowed to use .htaccess, so check on the relevant AllowOverride directive in your apache config.

Then try it this way in your <DocumentRoot>/.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/drupal.*
RewriteRule ^/(.*)$ /drupal/$1 [P]

RewriteCond ensures that you do not run into an infinite loop. The first part of the RewriteRule is always the URL requested by the client. We prefix the part matched inside the parentheses with /drupal/ and force it to be a proxy request via [P] so that apache would only do an internal redirect (instead of sending the client a "Document has moved" redirection code).

BTW: I did not test it. I may have typos in the code. Read http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule for more information.

maligree
No, ensignavenger wants it the other way around. You described the "normal" version most people ask for.
Paul
You mean he moved drupal to DocumentRoot? Okay, then your answer would be correct, Paul. Still, `RewriteEngine On` and the stuff about `AllowOverride` still applies.
maligree
Thanks, I was trying to do the opposite- the site was originally built in the /drupal directory, then I moved all the files to the root directory, which works fine, except the images and some of the links in the content still pointed to the old /drupal path. I was able to use the Redirect manager that my web host provides to configure the redirect! Your answer provided was very thorough, and provides great info!
ensignavenger