Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

htaccess file and mod rewrite for domain redirection

Posted on 2004-07-31
11
Medium Priority
?
238 Views
Last Modified: 2010-03-04
This is what I have so far:

RewriteEngine on

RewriteCond %{HTTP_HOST} www.domain.com
RewriteRule ^(.*) http://www.newdomain.com/$1 [L,R=301]

This is what I want to do:

1)  I want it to direct domain even if the user does not type www into the browser.  I am new to this and do not know the syntax.  Please give example and explain the syntax.

2) I was also wondering if there was a way to direct EVERYTHING to my main domain.  For example if the user types in anything that is pointed to my IP that it will send him to the main domain. Like a wildcard I guess.  Also what is the syntax?

3) Now that I have my domains redirected, I want to take care of the robots.txt files so certain robots do not index the domains that are being redirected.  How do I serve up an alternate robot txt file for anything other than my main domain?

4)  I am wanting to host two different sites from the same webspace.  How (through the htaccess file) would I point www.domain1.com to a subdirectory and use the files within that subdirctory but keep www.domain1.com/ in the browser address bar.  Would this create a problem with a robot indexing my site or would it still index my main site?  
0
Comment
Question by:killer455
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
11 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 700 total points
ID: 11687599
1) this is a browser and/or DNS issue, not a one for the web server (or have you virtual hosts with and without www. ?)
2) RewriteCond %{HTTP_HOST} !^www.domain.com$
     RewriteRule ^(.*) http://www.newdomain.com/$1
3) RewriteCond %{HTTP_HOST} !^www.domain.com$
     RewriteCond %{REQUEST_URI} .*/robots.txt
     RewriteRule ^(.*) http://www.newdomain.com/whaever-you-want.txt
4) RewriteCond %{HTTP_HOST} ^www.domain1.com$
     RewriteRule ^(.*) http://www.domain1.com/app1/$1[P]
0
 

Author Comment

by:killer455
ID: 11688516
Ok could you explain a few things.

1)  Basically if the user types in http://domain.com or http://www.domain.com I want to make sure it is redirected to the http://www.newdomain.com

2)I do not understand the #2 above.  Does the !^ "mean everything but"

Also I want these to be 301 redirection, for search engine optimization.  On the first one I had, I had [L,R=301]

Also what does the L stand for in this one?  

(Points increased)
0
 

Author Comment

by:killer455
ID: 11688548
Another question, with my comment from above,
2)I do not understand the #2 above.  Does the !^ "mean everything but"

Shouldnt it be:
RewriteCond %{HTTP_HOST} !^www.newdomain.com$
RewriteRule ^(.*) http://www.newdomain.com/$1

www.newdomain.com under rewritecond instead of www.domain.com
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:killer455
ID: 11688714
I have this right now, but it has a problem.
Whenever someone types in www.domain2.com/robots.txt
They are simply redirected to www.domain1.com/robots.txt
They are not send robots_noindex.txt

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www.domain1.com$ [NC]
RewriteRule (.*) http://www.domain1.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www.domain1.com$ [NC]
RewriteCond %{REQUEST_URI} .*/robots.txt
RewriteRule ^(.*) http://www.domain1.com/robots_noindex.txt
0
 

Author Comment

by:killer455
ID: 11688734
Also why do some write !^domain/.com
0
 

Author Comment

by:killer455
ID: 11689014
Started new thread, I have gotten a bit further with this.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11689326
>  Also why do some write !^domain/.com
  ! means *does not match*

> They are not send robots_noindex.txt
   RewriteCond %{HTTP_HOST} ^www.domain2.com$
   RewriteCond %{REQUEST_URI} ^/robots.txt$
   RewriteRule ^(.*) http://www.newdomain.com/robots_noindex.txt

also keep in mind that the sequence of the rules count
0
 

Author Comment

by:killer455
ID: 11689357
I want it to send the noindex.txt for EVERY domain other than the main.
You can drop this post if you want, i have added another.

http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_21078537.html
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11689411
ok, understand

BTW, I'd recommend that you post *one* question for each (4 here)
  that's not to force you spending points, but the resukts in the question are better if experts can focus on one problem per thread
0
 

Author Comment

by:killer455
ID: 11689473
ok will do
0
 

Author Comment

by:killer455
ID: 11689496
sorry for the extra post but to let you know,
I skimmed down my most recent posts into one question each.

thanks for the continued help
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question