mod_rewrite and host redirection

mod_rewrite and host redirection

am 20.08.2007 01:31:55 von leo

Hi,

Before I start, I probably ought to emphasise that what I'm trying to
achieve isn't the 'correct' way of doing things - it's a fudge due to
hosting provider limitations.

I have two domains pointing to the same docroot. I'm trying to get it so
that the second of the two domains points to a subdirectory within that
docroot but to no avail - just get an Error 500. I don't want this to be
a redirect which is visible to the user.

How would you go about doing this with mod_rewrite? Here's what I've got
thus far to redirect domain2 into a subdirectory on domain1

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain2\.com [NC]
RewriteRule ^(.+)$ /domain1subdir/$1

L.

Re: mod_rewrite and host redirection

am 20.08.2007 08:39:35 von unknown

Post removed (X-No-Archive: yes)

Re: mod_rewrite and host redirection

am 20.08.2007 22:33:41 von leo

>>How would you go about doing this with mod_rewrite? Here's what I've got
>>thus far to redirect domain2 into a subdirectory on domain1
>>
>>RewriteEngine on
>>RewriteCond %{HTTP_HOST} ^www\.domain2\.com [NC]
>>RewriteRule ^(.+)$ /domain1subdir/$1
>
>
> It works for me, just tried on a test machine and it works. The only
> difference is that I uses ^(.*)$ instead of ^(.+)$.
>
> Check the error_log, there must be something that justify the error 500
>
The problem now is that it just redirections domain2 at the docroot of
domain 1 not of a subfolder

Re: mod_rewrite and host redirection

am 21.08.2007 08:41:33 von unknown

Post removed (X-No-Archive: yes)

Re: mod_rewrite and host redirection

am 21.08.2007 11:53:54 von leo

> > The problem now is that it just redirections domain2 at the docroot of
> > domain 1 not of a subfolder
>
> and what did you changed?

In the docroot of domain1, .htaccess reads
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain2\.com
RewriteRule ^(.+)$. /domain2content/$1

Re: mod_rewrite and host redirection

am 21.08.2007 11:58:23 von unknown

Post removed (X-No-Archive: yes)

Re: mod_rewrite and host redirection

am 25.08.2007 17:37:16 von leo

Davide Bianchi wrote:
> On 2007-08-21, Leo wrote:
>
>>In the docroot of domain1, .htaccess reads
>
>
> I don't think that will work in an .htaccess, since that is accessed
> only if you access that directory. I think you need to put that in your
> httpd.conf file. This is where I put, and it works fine even for subdir.
>
> Davide
>

Sorted it! OK it's a bit of a ropey way of doing it but I set it up
using the [P] flag

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain2.com$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/subdir/$1 [P]