Forum Moderators: phranque

Message Too Old, No Replies

Redirect blog.mainsite.com to tempsite.com/blog

         

BrianBoyko

10:23 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



Hi. I came into this company about a year into this project - I'm kind of a writer, so I'm usually not dealing with code, but I have to set this up.

Here's the situation:

The company hired a subcontrator to create two Web sites, www.mainsite1.com and www.mainsite2.com.

Now that I'm onboard, they want blogs for both sites.

Now, it'd cost a heck of a lot of money to set up a wordpress account and forum with the subcontractor - so what we're doing (for right now) is hosting the blogs with dreamhost on tempsite.com/blog1 and tempsite.com/blog2

blog.mainsite1.com and blog.mainsite2.com already points to the IP address of the tempsite.com, but I need to know how to configure the .htaccess files so that:

a) blog.mainsite1.com redirects to tempsite.com/blog1, and blog.mainsite2.com redirects to tempsite.com/blog2.

b) To the end user, it all looks like it's taking place on blog.mainsite1.com and blog.mainsite2.com. They should never even see "tempsite.com" in the URL.

Anyone ever dealt with this, or know how to do it?

g1smd

10:31 pm on Mar 9, 2010 (gmt 0)

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



You don't need a redirect to serve the content as you describe, you need a rewrite for each sub-domain each mapping to the respective folder.

In order to stop direct access to tempsite.com/blog1 and tempsite.com/blog2 you need a redirect from those folder URLs back to the subdomain URLs but only for direct client requests.

There's very many prior examples in this forum, as it is a question that is usually asked several times each month. Many threads have answers with complete code examples which can be adapted.

BrianBoyko

10:51 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



So this would work?

RewriteEngine On
RewriteRule blog.mainsite1.com /home/USER/tempsite.com/blog1/
RewriteRule blog.mainsite2.com /home/USER/tempsite.com/blog2/

g1smd

11:04 pm on Mar 9, 2010 (gmt 0)

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



Test the value of HTTP_HOST using a preceding RewriteCond for each rule.

Be aware that RewriteRule sees only the path part of the URL request, not the host name or any query string parameters.

Each rule needs the [L] flag. Check out the resources in cited in the forum charter for examples.

BrianBoyko

11:04 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



You've lost me.

Why would I need to test the value of HTTP_HOST? And test it for -what?-

What's RewriteCond?

I don't know what an [L] flag is, or why I need it.

You have to understand, the last time I did web dev was in 1997. I'm a copywriter now. :(

BrianBoyko

11:14 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



This is what I've got so far:

RewriteEngine On

RewriteCond %{REMOTE_ADDR} ^blog.mainsite1.com$
RewriteRule ^blog.mainsite1.com$ /home/user/tempsite.com/blog1/ [L]

RewriteCond %{REMOTE_ADDR} ^blog.mainsite2.com$
RewriteRule ^blog.mainsite2.com$ /home/user/tempsite.com/blog2/ [L]

BrianBoyko

11:22 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



Maybe this will work. I don't know.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^blog.mainsite1.com$
RewriteRule ^blog.mainsite1.com$ /home/user/tempsite.com/blog1/ [L]

RewriteCond %{HTTP_HOST} ^blog.mainsite2.com$
RewriteRule ^blog.mainsite2.com$ /home/user/tempsite.com/blog2/ [L]

jdMorgan

7:50 pm on Mar 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is likely that

RewriteEngine On
#
RewriteCond %{HTTP_HOST} ^blog\.mainsite1\.com
RewriteRule ^(.*)$ /home/user/tempsite.com/blog1/$1 [L]
#
RewriteCond %{HTTP_HOST} ^blog\.mainsite2\.com
RewriteRule ^(.*)$ /home/user/tempsite.com/blog2/$1 [L]

would be closer to what you need for the first step that g1smd outlined above. I can't tell, but all or part of the "/home/user/tempsite.com" path may be unnecessary -- you'll have to test to see, though, as there's no way we can tell from here.

Based on the improvement in your coding attempts, it looks like you've found the Apache mod_rewrite documentation by now. If not, check out the resources cited in our Apache Forum Charter to understand the changes I propose to the code that you posted.

Jim