Solved

htaccess file and mod rewrite for domain redirection

Posted on 2004-07-31
11
237 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 175 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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