homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirecting a 2nd domain to an inner page of main site
How to code .htaccess?
spina45




msg:3384251
 4:00 pm on Jul 2, 2007 (gmt 0)

I'm not a programmer. I just purchased several new domain names BUT rather than simply pointing them to my existing domain, I'd like to point them to specific inner pages of my existing site.

Below is an example of what I currently have in my .htaccess.

Can anyone offer code examples of how I can get NEW-DOMAIN.com to point to EXISTING-DOMAIN/SPECIFIC-PAGE.html?

Thank you very much.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^EXISTING-DOMAIN\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^NEW-DOMAIN\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.) NEW-DOMAIN\.com [NC,OR]
RewriteRule (.*) [EXISTING-DOMAIN.com...] [R=301,L]

 

jdMorgan




msg:3384319
 4:59 pm on Jul 2, 2007 (gmt 0)


Options +FollowSymLinks
RewriteEngine on

# Redirect to add "www" prefix for existing or new domain
RewriteCond %{HTTP_HOST} ^existing-domain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^new-domain\.com [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

# Internally rewrite new domain home page requests to a specific page
RewriteCond %{HTTP_HOST} ^www\.newdomain\.com
RewriteRule ^$ /specific-page.html [L]

This will serve the page "/specific-page.html" whenever "new-domain.com/" or "www.newdomain.com/" is requested. The page will appear to reside in its own domain, i.e. the browser address bar will show "www.newdomain.com/"

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

spina45




msg:3384479
 8:09 pm on Jul 2, 2007 (gmt 0)

Thank you very much. I will study and also read links you provided.

Question:

Based on what you said it seems that "specific-page" will be accessible via two differnt urls:

1) new-domain.com
2) existing-page-name.html

Bacause of the bad news re: Google and duplicate content, is there anyway to force new-domain.com to only show existing-page-name.html and not cuase any problems that Google or other SEs will trip on?

jdMorgan




msg:3384484
 8:20 pm on Jul 2, 2007 (gmt 0)

Yes, there is a way to do that, but it would be wise to get the above code tested and working before adding another layer of complexity to it... :)

Jim

spina45




msg:3384487
 8:28 pm on Jul 2, 2007 (gmt 0)

Thank you for your reply.

I will do what you say.

But is there any way could you post the additional code lines? The reason it's important to me is because as soon as the first layer is running smoothly and tested I would want to add the additional layer immediately to avoid ANY Google duplicate content penalties.

I just got out of Google hell after more than 11 months.

jdMorgan




msg:3384503
 9:07 pm on Jul 2, 2007 (gmt 0)

I'd rather not try to add any more complexity until you've tested the first part. Your testing may indicate that a change is needed, and that change may require even more work if we further complicate things. You are not going to have additional problems because you don't have the second part. It's just that without the second part, you won't fix all of the potential problems at once.

However, if we code both parts, and I am wrong about one little detail in both parts, then you will have twice the problem you would have if only the first part was wrong...

Also, I must choose how to spend my time here, so I must ask you to test the first part before going any further... Thanks.

Jim

spina45




msg:3384520
 9:39 pm on Jul 2, 2007 (gmt 0)

Understood. Thank you.

Once it's working and tested. I can ** comment it out until ready to move on to phase two. Thank you again for your help. Most appreciated.

spina45




msg:3385730
 3:02 am on Jul 4, 2007 (gmt 0)

Hello jdMorgan,

Thank you for your code examples. I could not get them to work how I wanted. :(

I have one main-domain and 12 pointer-domains. I want all domains to resolve to: www.main-domain.com. The code below DOES accomplish this.

I also do not want to display index.html or index.htm. The code below DOES accomplish this.

MY CHALLENGE:

Have www.pointer-domain1.com AND pointer-domain1.com both point to an inner page of my site and show the inner-page url in the browser bar. For example, this page:

www.main-domain.com/store/specific-inner-page.html

Can you suggest code that will work in harmony with what I currently have?

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^main-domain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^ pointer-domain1\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)? pointer-domain1\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^ pointer-domain2\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)? pointer-domain2\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^ pointer-domain3\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)? pointer-domain3\.com [NC]
RewriteRule (.*) [main-domain.com...] [R=301,L]
RewriteRule ^(([^/]+/)*)index\.html$ [main-domain.com...] [R=301,L]
RewriteRule ^(([^/]+/)*)index\.htm$ [main-domain.com...] [R=301,L]

Thank you.

jdMorgan




msg:3385760
 3:49 am on Jul 4, 2007 (gmt 0)

It's fairly simple, and I'm not sure why you couldn't derive it for yourself... If you try and test and retry and re-test a few times, it'll still likely be far faster than waiting for a reply here...

You've introduced some unnecessary redundancy; Don't duplicate RewriteConds and RewriteRules for www- or non-www and "html" or "htm" -- Use the power of regular expressions to handle optional characters and groups of characters:

Options +FollowSymLinks
RewriteEngine On
#
# Redirect "/index.html" or "/index.htm" to "/" {in any (sub)directory}
# (Use THE_REQUEST to prevent a loop caused by interaction with DirectoryIndex)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?[^\ ]*\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://%{HTTP_HOST}/$1 [R=301,L]
#
# Redirect pointer-domain1/ or www.pointer-domain1/ to specific page
RewriteCond %{HTTP_HOST} ^(www\.)?pointer-domain1\.com [NC]
RewriteRule ^$ http://www.main-domain.com/store/specific-inner-page.html [R=301,L]
#
# Redirect all other non-canonical (www- or non-www) domains to the canonical domain
RewriteCond %{HTTP_HOST} ^main-domain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?pointer-domain2\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?pointer-domain3\.com [NC]
RewriteRule (.*) http://www.main-domain.com/$1 [R=301,L]

Jim

[edited by: jdMorgan at 4:37 am (utc) on July 4, 2007]

spina45




msg:3386297
 6:49 pm on Jul 4, 2007 (gmt 0)

THANK YOU!

It all works nicely and my .htaccess is now very tidy. In addition to providing me the answers, thank you also for the tips on improving code performance. This is not my area of expertise; I generally only modify .htacess a couple of times a year.

Sincere thanks.

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