Solved

htaccess file and mod rewrite for domain redirection

Posted on 2004-07-31
11
235 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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