Forum Moderators: phranque

Message Too Old, No Replies

redirect new domain to sub-dir of old domain

problem not showing url correctly

         

xafier

10:32 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



Hi,
I'm trying to get a new domain "newdomain.co.uk" to re-direct to a sub directory on another domain "olddomain.com". I've got this to work, but the problem is that its not showing how I want it to in the browsers url bar (neither IE or Firefox).

I'm pretty sure I've just got some flag wrong but I cant figure where... any help?

Options +FollowSymLinks
Options +SymlinksIfOwnerMatch

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^newdomain\.co.uk [NC]
RewriteRule ^.*$ [newdomain.co.uk%{REQUEST_URI}...] [R=permanent,L]

RewriteCond %{HTTP_HOST} ^www.newdomain.co.uk [NC]
RewriteRule ^.*$ [olddomain...] [L]

thats the code I'm using...
but when the user types in "www.newdomain.co.uk" I want it to show that, not re-direct and show www.olddomain.com/forumdir/

any suggestions? thanks :)

jdMorgan

1:35 am on Mar 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



xafier,

Welcome to WebmasterWorld!

Are both domains hosted on the same server?

Jim

xafier

10:29 am on Mar 26, 2005 (gmt 0)

10+ Year Member



not 100% sure what your asking here so I'll try and explain the best I can:

www.olddomain.com is what I use for my personal web-site, I started a forum the other day that has started to take off quite quickly and so I decided I'd get a new domain to point directly to the forum that is easier to remember than www.olddomain.com/theforumsname/

so technically yes both domains are pointing to the same server, but if someone is requesting www.newdomain.co.uk I want to filter that and take them to the forum, which it's now doing, but its displaying things like www.olddomain.com/theforumsname/index.php?showtopic=22

whereas I want it to display www.newdomain.com/index.php?showtopic=22 so basically I just don't want people to know that its on the same server as my personal web-site.

The reason I didn't go for a new host is because the web-host I'm with is a LOT cheaper than anyone else I've found and I have plenty of spare drive space and bandwidth.

jdMorgan

2:16 am on Mar 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My point was that your problem, as defined, would be difficult to solve if the domains resolved to separate physical servers. To get to another server, you'd have to do an external redirect, which would unavoidably show the actual domain name. (There's one exception, and that is if one of the machines acts as a proxy for the other, but thankfully, we don't need to get into that.)

A simple way to rephrase and answer my question is, "If you remove all rewrites related to /forumdir, can you currently access the forum directory as 'http://www.olddomain.co.uk/forumdir/' and as 'http://www.newdomain.co.uk/forumdir/'?"

If so, you should be able to use the following, unless there are other requirements outside what's been discussed:


Options +FollowSymLinks
RewriteEngine on
#
# Redirect newdomain to www.newdomain
RewriteCond %{HTTP_HOST} ^newdomain\.co\.uk [NC]
RewriteRule (.*) http://www.newdomain.co.uk/$1 [R=301,L]
#
# Rewrite all pages requested from newdomain to same-named pages in /forumdir/
# (Added RewriteCond to prevent infinite loop)
RewriteCond $1 !^forumdir/
RewriteCond %{HTTP_HOST) ^www\.newdomain\.co\.uk [NC]
RewriteRule (.*) /forumdir/$1 [L]

[added]
And further, you can forbid "direct access" (e.g. type-in URL access) to olddomain/forumdir and newdomain/forumdir by adding the following ruleset between the two above:

RewriteCond %{THE_REQUEST} \ /forumdir/
RewriteRule . - [F]

This will not affect the internal rewrite. It will only affect direct outside requests for the "hidden" /forumdir. You could also choose to redirect the direct /forumdir requests, rather than returning a forbidden response, but I wouldn't recommend that unless it's absolutely necessary.
[/added]

Jim