Solved

htaccess file and mod rewrite for domain redirection

Posted on 2004-07-31
11
229 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now