mod_rewrite and host redirection

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.
leo [ Mo, 20 August 2007 01:31 ] [ ID #1799957 ]

Re: mod_rewrite and host redirection

Post removed (X-No-Archive: yes)
Notifier Deamon [ Mo, 20 August 2007 08:39 ] [ ID #1799962 ]

Re: mod_rewrite and host redirection

>>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
leo [ Mo, 20 August 2007 22:33 ] [ ID #1799990 ]

Re: mod_rewrite and host redirection

Post removed (X-No-Archive: yes)
Notifier Deamon [ Di, 21 August 2007 08:41 ] [ ID #1801311 ]

Re: mod_rewrite and host redirection

> > 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
leo [ Di, 21 August 2007 11:53 ] [ ID #1801313 ]

Re: mod_rewrite and host redirection

Post removed (X-No-Archive: yes)
Notifier Deamon [ Di, 21 August 2007 11:58 ] [ ID #1801315 ]

Re: mod_rewrite and host redirection

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]
leo [ Sa, 25 August 2007 17:37 ] [ ID #1805028 ]
Webserver » alt.apache.configuration » mod_rewrite and host redirection

Vorheriges Thema: Using files on network drives in windows
Nächstes Thema: .htaccess ForceType unnecessary for images?