views:

387

answers:

2

Hi,

I am trying to redirect all requests coming from example.com to a subdirectory. The code below accomplishes this but I cannot make the subdirectory invisible. (The subdirectory contains a Drupal instance with its own/htaccess file. Could that be the problem?)

  RewriteCond %{HTTP_HOST} ^example.com$ [NC]

  RewriteRule ^(.*)$ http://example.com/drupal/d6/$1 [L]

This ends up looking like this in the browser:

http://example.com/drupal/d6/install.php?profile=default

EDIT: I tried removing http://example.com from the RewriteRule, as recommended, but the redirect is still not invisible. :-(

A: 

You need to rewrite to the location, not to a full http:// URL. If you do it to a URL then a redirect is issued even without the [R] flag on the RewriteRule. Go instead to /drupal/d6/$1 and it should stay a rewrite (rather than "upgrading" to a redirect).

From http://httpd.apache.org/docs/2.2/mod/mod%5Frewrite.html

Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection.
Ry4an
It only issues a redirect if you do [R] or if you have a ht_tp:// start.
Ry4an
WHen I do that I get a "Server Error." And in the error log I see this: [Fri Aug 28 14:04:51 2009] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
picardo
Ok, I fixed the server error, which was caused by a typo, but it still doesn't make the URL invisible.
picardo
RewriteRule ^(.*)$ /drupal/d6/$1should be all that's required. Is drupal issuing the redirect to ?profile=default? Do you still see /drupal/d6/ if you start out going to http://example.com/?profile=defaultAt this point if there are no errors to look at I'd turn on the RewriteLog and see exactly what's modifying the URL and where. You should be able to do this w/o a 30x redirect being issued (and without a proxy)
Ry4an
A: 

An absolute URl will cause a redirect. Use just a path:

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteCond $0 !^drupal/d6/
RewriteRule .* drupal/d6/$0 [L]
Gumbo
I tried this but the url still looks like http://example.com/drupal/d6/install.php?profile=default. Do you know how I can make the drupal/d6 invisible?
picardo
@picardo: So you also want a rule that removes `/drupal/d6` from the URL if requested?
Gumbo
@gumbo Yes, precisely.
picardo