Welcome to WebmasterWorld Guest from 54.163.168.15

Forum Moderators: Ocean10000 & incrediBILL & phranque

Redirecting Domains to subpages of other domains

Using Apache Server

   
5:04 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm hoping this should be a reasonably easy feat, but I have been struggling with finding a good way to do this.

Here's my quandry:

Site: www.examplesite.com
This is my main site.

I would like www.anotherexamplesite.com
to be directed to:
www.examplesite.com/oneofthepropertiesdirectory/index.htm

I am using apache server, and hoping to do this for a couple different domains to give our different properties more easily marketable domains.

I have done page redirects in the httpd.conf file but can't seem to figure out how to redirect an entire domain.

Any help would be greatly appreciated.

[edited by: DaveAtIFG at 6:57 pm (utc) on Sep. 15, 2003]
[edit reason] URLs generalized [/edit]

6:49 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Administrator bakedjake is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Off the top of my head:


RewriteEngine on
RewriteRule ^www\.([^.]+)\.com(.*) http://www.examplesite.com/$1/$2

This should take the hostname used, and redirect it to the subdirectory (same name as the domain name) under the main site, and also pass long any pages requested.

[edited by: DaveAtIFG at 6:58 pm (utc) on Sep. 15, 2003]
[edit reason] URLs again [/edit]

7:04 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



stuntdubl,

External redirect - New URL shows in user's browser:


RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?examplesite\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.com
RewriteRule ^(.*)$ http://www.examplesite.com/%2/$1 [R=301,L]

Internal redirect - New URL does not show in user's browser:


RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?examplesite\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.com
RewriteRule ^(.*)$ /%2/$1 [L]

In each case, the first RewriteCond is intended to prevent an "infinite loop" on your server.

Jim

[edited by: DaveAtIFG at 7:23 pm (utc) on Sep. 15, 2003]
[edit reason] More URLs! [/edit]

8:22 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?examplesite\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.com
RewriteRule ^(.*)$ [examplesite.com...] [R=301,L]

This sounds good. Is there a certain place I place this in the httpd.conf file?

Can you also please provide me a little insight into where the first-domain-to-be-redirected.com and the redirected-to-site.com/site-dir/page.htm would go? Could you please clarify?

I tried to use generic terms in the first post, but I guess not generic enough.

Many thank you's.

10:25 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



stuntdubl,

This is for .htaccess in the web root of the site itself. If you're going to put this in a <directory> container in httpd.conf, it will require modification:


RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?requested_site\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.com
RewriteRule [b]^/([/b].*)$ http://www.target_site.com/%2/$1 [R=301,L]

I'm not sure whether your question is about patterns versus substitutions, or about backreferences; If you have any questions about what is what, I strongly advise you to read the Apache mod_rewrite documentation [httpd.apache.org] before proceeding - mod_rewrite is strong medicine...

Jim

4:50 pm on Sep 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I put the code in the root <directory "/"> tag.

I printed and tried to read the documentation last night, and again this morning but it pretty much goes right over my head.

From what I gather, it looks like that code should work, but the only part that throws me is the:

RewriteRule ^/(.*)$ [target_site.com...]
What is the /%2/$1 for?
I want redirect the requested_site to a specific file in the target site.

This is for .htaccess in the web root of the site itself. If you're going to put this in a <directory> container in httpd.conf, it will require modification:

A bit off-subject here but......Am I correct in assuming if I place a file in the root directory named ".htaccess" it will be found and executed by the server? I remember trying this before and only having success in configuring with the httpd.conf file (although it seemed that .htaccess was turned on in the httpd.conf file)

I'm not sure whether your question is about patterns versus substitutions, or about backreferences; If you have any questions about what is what, I strongly advise you to read the Apache mod_rewrite documentation before proceeding - mod_rewrite is strong medicine...

I'm not real sure either....I am very careful to change anything back to its original state if it doesn't have the intended effect though. I'm kinda skiddish about messin' with our webserver too aweful much.

One last note.....I'm not sure what (if any) difference this will make, but our "host" (provider of our T1) point the "requested_site" to the TOP LEVEL of the domain that contains the file I want to redirect to.

5:26 pm on Sep 16, 2003 (gmt 0)

10+ Year Member



From your first message, this is what you want to do:

Site: www.examplesite.com
This is my main site.
I would like www.anotherexamplesite.com to be directed to:
www.examplesite.com/oneofthepropertiesdirectory/index.htm

You just want to redirect all requests to anotherexamplesite.com to a page in a directory in examplesite.com. So here's what you would put in the <Directory> container:

RewriteEngine on


RewriteCond %{HTTP_HOST} ^(www\.)?anotherexamplesite\.com
RewriteRule .* http://www.examplesite.com/oneofthepropertiesdirectory/index.htm [R=301,L]

If you have other domains, you would just have to add additional RewriteConds and RewriteRules for each one.

Am I correct in assuming if I place a file in the root directory named ".htaccess" it will be found and executed by the server? I remember trying this before and only having success in configuring with the httpd.conf file (although it seemed that .htaccess was turned on in the httpd.conf file)

Yes, but only if AllowOverride, which you can set in httpd.conf, is not set to none. When you have a choice between using .htaccess and httpd.conf, you should choose httpd.conf. You can learn more about these two points here [httpd.apache.org].
7:28 pm on Sep 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for all your help guys.

I have tried both methods, and neither seem to work. The site is still be redirected to the top level of the primary domain.

Are the settings of my ISP overriding mine? Or am I missing something. I've double checked the code, and I didn't get any errors when I restarted the webserver.

Any ideas? I have the code listed in <directory "/">

5:23 am on Sep 17, 2003 (gmt 0)

10+ Year Member



Beats me.

What do your log files say when you access anotherexamplesite.com? Do you see anything suspicious there?

10:08 am on Sep 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jim:

>>Internal redirect - New URL does not show in user's browser:

RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?examplesite\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.com
RewriteRule ^(.*)$ /%2/$1 [L]
<<

Can one also use this method for hiding a .zip file for downloads so it cannot be leached? Example, I have a script that adds to a log when someone downloads the program, but you can see the URL in the browser, so they can just build a link to the .zip file. Will this hide the URL?

2:55 pm on Sep 18, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



jim_w,

Yes and no. But it's not on-topic for this thread.

Jim

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month