Apache Server configuration support - mod_rewrite and host redirection

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > August 2007 > mod_rewrite and host redirection





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author mod_rewrite and host redirection
Leo

2007-08-19, 7:27 pm

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.
Davide Bianchi

2007-08-20, 4:11 am

On 2007-08-19, Leo <nobody@invalid.syntax> wrote:
> 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.


Can you see what kind of error is logged in the error_log?

> 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

Davide

--
Microsoft is a cross between The Borg and the Ferengi. Unfortunately they use
Borg to do their marketing and Ferengi to do their programming.
--Simon Slavin
Leo

2007-08-20, 7:26 pm


>
>
> 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
Davide Bianchi

2007-08-21, 7:23 am

On 2007-08-20, Leo <nobody@invalid.syntax> wrote:
> The problem now is that it just redirections domain2 at the docroot of
> domain 1 not of a subfolder


and what did you changed?
Davide

--
Using OpenOffice instead of Microsoft Office is like eating organic food
instead of conventional. It is not the experience, or the expense, or the
convenience that matters. It is the knowledge that you are a better person
for so doing. --Verity Stob
Leo

2007-08-21, 7:23 am

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


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

Davide Bianchi

2007-08-21, 7:23 am

On 2007-08-21, Leo <leo.andrews@gmail.com> 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

--
Oh My God! They Killed init! You Bastards!
-- From a Slashdot.org post
Leo

2007-08-25, 1:24 pm

Davide Bianchi wrote:
> On 2007-08-21, Leo wrote:
>
>
>
> 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]
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com