change default index.html file for specific domain name

New to mod_rewrite? This is a good place to start.

change default index.html file for specific domain name

Postby anarchoi » Fri May 22, 2009 12:38 am

hello,

i have two domain names pointing on a same folder of my site

basically i would just like to have a different index.html when accessing the second domain name

exemple:

domain1.com and domain2.com are pointing to the root folder of my server
so normally when accessing domain1.com or domain2.com, "index.html" file will be displayed

i would like to display "another_page.html" instead of "index.html" but ONLY when accessing domain2.com

could please someone help me?
anarchoi
 
Posts: 23
Joined: Mon Apr 23, 2007 9:42 pm

Postby richardk » Fri May 22, 2009 8:24 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule ^$ /another_page.html [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby anarchoi » Sat May 23, 2009 4:27 am

thanks,

but if i want to change "domain1.com" to a subdomain like "http://subdomain.mysite.com" what do i have to do?
anarchoi
 
Posts: 23
Joined: Mon Apr 23, 2007 9:42 pm

Postby richardk » Sat May 23, 2009 4:13 pm

Replace
Code: Select all
^(www\.)?domain2\.com$

with
Code: Select all
^subdomain\.example\.com$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby RaiD » Fri Jun 05, 2009 7:42 am

My apologies if I'm hijacking this thread, but I have a question along these lines...

I am trying to accomplish the following:

-Our company owns several domain names and I'd like whichever domain the user enters in to be redirected to a corresponding page on our "main" domain.

-If someone puts in http://domain.com (with or without www), I'd like to redirect them to http://www.maindomain.com/page.htm.

AND

-If someone puts in http://domain.com/page.htm (with or without www), I'd like to redirect them to http://www.maindomain.com/page.htm.

The page.htm file will be different depending on what domain the user entered in (domain1.com will go to maindomain.com/page1.htm, domain2.com will go to maindomain.com/page2.htm). Even if the user doesn't enter in the specific page name for the old domain, I would still like them to be directed to maindomain.com/page1.htm because the domain name itself is descriptive. Below is the code I have so far:

Code: Select all

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule ^$ http://www.maindomain.com/page2.html [R=301,QSA,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain3\.com$ [NC]
RewriteRule ^$ http://www.maindomain.com/page3.html [R=301,QSA,L]



Can I also add in the following code to make sure that IF the user enters in the page directly (instead of just the domain name), that they will be directed to the maindomain.com? ie. user types in "domain1.com/page1.htm" that they be directed to "maindomain.com/page1.htm"?

Code: Select all

#redirect domain1/page1.htm to domain/page1.htm
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^(.*)\.htm$ http://www.domain.com/$1.htm [R=301,L]



Thanks!
Ryan
RaiD
 
Posts: 2
Joined: Fri Jun 05, 2009 6:29 am

Postby richardk » Fri Jun 05, 2009 10:56 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule ^(page2\.html)?$ http://www.maindomain.com/page2.html [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby RaiD » Fri Jun 05, 2009 12:49 pm

Damn I was close...but you were dead on. :)

Thanks richardk!!
RaiD
 
Posts: 2
Joined: Fri Jun 05, 2009 6:29 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 100 guests

cron