homepage Welcome to WebmasterWorld Guest from 54.147.196.159
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirecting Domains to subpages of other domains
Using Apache Server
stuntdubl

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 388 posted 5:04 pm on Sep 15, 2003 (gmt 0)

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]

 

bakedjake

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



 
Msg#: 388 posted 6:49 pm on Sep 15, 2003 (gmt 0)

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]

jdMorgan

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



 
Msg#: 388 posted 7:04 pm on Sep 15, 2003 (gmt 0)

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]

stuntdubl

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 388 posted 8:22 pm on Sep 15, 2003 (gmt 0)

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.

jdMorgan

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



 
Msg#: 388 posted 10:25 pm on Sep 15, 2003 (gmt 0)

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

stuntdubl

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 388 posted 4:50 pm on Sep 16, 2003 (gmt 0)

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.

closed

10+ Year Member



 
Msg#: 388 posted 5:26 pm on Sep 16, 2003 (gmt 0)

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].

stuntdubl

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 388 posted 7:28 pm on Sep 16, 2003 (gmt 0)

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 "/">

closed

10+ Year Member



 
Msg#: 388 posted 5:23 am on Sep 17, 2003 (gmt 0)

Beats me.

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

jim_w

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 388 posted 10:08 am on Sep 18, 2003 (gmt 0)

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?

jdMorgan

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



 
Msg#: 388 posted 2:55 pm on Sep 18, 2003 (gmt 0)

jim_w,

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

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved