Forum Moderators: phranque

Message Too Old, No Replies

Redirecting an Addon Domain to a Subfolder

         

Deemer

5:22 pm on Nov 22, 2008 (gmt 0)

10+ Year Member



I have searched almost everywhere and tried many examples, but I have not found a solution. I have Apache running perfectly with one domain, and I have recently purchased another domain for a separate site which is currently located at http://example.com/subfolder. I am attempting to redirect all queries for the second domain to the subfolder without changing the URL.

I found the following rewrite code, which is now in a .htaccess file in Apache's root directory and the subfolder:

RewriteEngine on
Options +FollowSymlinks
#
RewriteCond %{HTTP_HOST} ^(www\.)?otherdomain\.com
RewriteCond %{REQUEST_URI} !/subfolder/
RewriteRule (.*) /subfolder/$1 [L]

This is working perfectly for direct requests to [otherdomain.com,...] however a request to a URL such as [otherdomain.com...] fail with a 404 by redirecting to http://example.com/somesubfolder/

Thanks in advance.

ajcoon

7:36 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



Can you please clarify your intention? Is it that you want to concatenate the extended URL onto the new URL? Or are you trying to truncate the extended URL of the incoming request and always have it re-written to the same thing?

g1smd

12:55 am on Nov 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This scenario was covered with lots of example code less than 2 weeks ago in some other thread here.

There is also some stuff in the sticky thread pinned at the top of the forum.

jdMorgan

1:53 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code looks correct. As written above, it should internally rewrite request for
otherdomain.com/<anything> to /subfolder/<anything>

That is, it should rewrite:
otherdomain.com/ to /subfolder/
otherdomain.com/folder/ to /subfolder/folder/
otherdomain.com/file to /subfolder/file
otherdomain.com/folder/file to /subfolder/folder/file

The same is true for folder/file requests using the "www.otherdomain.com" hostname.

The only things I can think of to recommend are to completely-flush your browser cache before testing any new server-side code, and to be sure that your rule is not getting interfered-with by other redirects, rewrites, or mod_dir or mod_alias directives.

Jim