Solved

htaccess file and mod rewrite for domain redirection

Posted on 2004-07-31
11
236 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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