Sivakatirswami
asked on
mod_rewrite C names to A names
I am a complete mod_rewrite new bie and despite review lots of answers, feel nervous about trying to adapt some answers that seem close to what i need, so let me ask this fresh:
For the domain hinduismtoday.com we have set the A name www.hinduismtoday.com to the IP. then we have several CName alias which resolve to the same IP but are entered in the DNS as "www.hinduism-today.com is an alias for www.hinduismtoday.com"
On some other domain's our DNS admin has not been consistent and he set other domain names up as A names to the same IP . we can convert those to Cnames if that helps us here...
what I want to do is have mod_rewrite take all alias url's and A name url pointing to the same IP and re-write them to one common, base A name. the goal here is simple: prevent search engines from indexing pages at a diversity of URL, when in fact they are all the same page on the same web site.
simply stated: if someone enters (or Google follow a link on a third party site to:) www.hinduism-today.com/ or any www.hinduism-today.com/*foofileOrDirectory/, we want Apache to return n: http://www.hinduismtoday.com//*foofileOrDirectory/ for all instances. This will let us set up site specific searching, which doesn't work now because Google's indexing of our sites is fragmented across a diversity of URL's. so, a site specific search will not pick up pages indexed until a CNAME url.
I know this has been asked and answered, but if someone could give me the mod_rewrite code for a .htaccess file test with a line by line brief explanation of what each line does, I will be most grateful! Also, let me know if having multiple Aname entries inthe DNS for the same IP will be handled the same by mod_rewrite, or if we should change all those to CNAMEs for the primary A NAME.
Thanks!
Sivakatirswami
For the domain hinduismtoday.com we have set the A name www.hinduismtoday.com to the IP. then we have several CName alias which resolve to the same IP but are entered in the DNS as "www.hinduism-today.com is an alias for www.hinduismtoday.com"
On some other domain's our DNS admin has not been consistent and he set other domain names up as A names to the same IP . we can convert those to Cnames if that helps us here...
what I want to do is have mod_rewrite take all alias url's and A name url pointing to the same IP and re-write them to one common, base A name. the goal here is simple: prevent search engines from indexing pages at a diversity of URL, when in fact they are all the same page on the same web site.
simply stated: if someone enters (or Google follow a link on a third party site to:) www.hinduism-today.com/ or any www.hinduism-today.com/*foofileOrDirectory/, we want Apache to return n: http://www.hinduismtoday.com//*foofileOrDirectory/ for all instances. This will let us set up site specific searching, which doesn't work now because Google's indexing of our sites is fragmented across a diversity of URL's. so, a site specific search will not pick up pages indexed until a CNAME url.
I know this has been asked and answered, but if someone could give me the mod_rewrite code for a .htaccess file test with a line by line brief explanation of what each line does, I will be most grateful! Also, let me know if having multiple Aname entries inthe DNS for the same IP will be handled the same by mod_rewrite, or if we should change all those to CNAMEs for the primary A NAME.
Thanks!
Sivakatirswami
Oh, wow. First line of the cheat sheet tells you exactly how to do it. :)
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
I hope this helps.
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
I hope this helps.
ASKER
Oh My Goodness! Let us hope is it that easy..
testing..... Hmmm doesn't work: my.htaccess at the top of the site:
errorDocument 404 /cgi-bin/redirect.cgi
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
try it:
http://www.hinduism-today.com/past_issues.shtml
Nothing happens to the URL. BTTDB (back to the drawing board) :-)
testing..... Hmmm doesn't work: my.htaccess at the top of the site:
errorDocument 404 /cgi-bin/redirect.cgi
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
try it:
http://www.hinduism-today.com/past_issues.shtml
Nothing happens to the URL. BTTDB (back to the drawing board) :-)
Let me doe some tests. I will post my results in a few minutes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh... "duh" "RewriteEngine On" was all that was missing..
OK it works!
try it:
http://www.hinduism-today.com/
now, how to handle multiple CNAMES ? just keep adding set of lines for each?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.hinduismtoday.org [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301]
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
This works, and doesnt' seem to cause any slow down... That cheat sheet was great... I actually understand the code... by removing the "L" flag at the end of the first interation, it drops through...seems to work fine, but my code brain thinks this is not very efficient... having to declare the re-write twice in the same loop. I mean, not a problem, I can live with it, but the little Obsessive Compulsive Clean Code Gremlin that lives on my left shoulder is frowning :-)
Thanks!
OK it works!
try it:
http://www.hinduism-today.com/
now, how to handle multiple CNAMES ? just keep adding set of lines for each?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.hinduismtoday.org [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301]
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
This works, and doesnt' seem to cause any slow down... That cheat sheet was great... I actually understand the code... by removing the "L" flag at the end of the first interation, it drops through...seems to work fine, but my code brain thinks this is not very efficient... having to declare the re-write twice in the same loop. I mean, not a problem, I can live with it, but the little Obsessive Compulsive Clean Code Gremlin that lives on my left shoulder is frowning :-)
Thanks!
Works perfectly, I got bounced to the non-hyphenated domain right away. Yeah, that cheat sheet is awsome. I bookmarked it because I always have problems writing rewrite conditions/rules.
As far as adding a loop mod_rewrite is just a type of "filter" and you need to just put statement after statement for all of the domains you want to be redirected but like you said, it doesn't cause any slowness or anything which is great. I've never had any problems with the mod_rewrite engine slowing anything down, even with complex .htaccess files.
Glad I could help.
As far as adding a loop mod_rewrite is just a type of "filter" and you need to just put statement after statement for all of the domains you want to be redirected but like you said, it doesn't cause any slowness or anything which is great. I've never had any problems with the mod_rewrite engine slowing anything down, even with complex .htaccess files.
Glad I could help.
ASKER
OK, yes, I thought I had tested this and it failed, but it is working now...
errorDocument 404 /cgi-bin/redirect.cgi
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteCond %{HTTP_HOST} ^www.hinduismtoday.org [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
Fabulous. Thank you for your "responsiveness" I mean, you turned this around about as fast as it could be...
Sivakatirswami
errorDocument 404 /cgi-bin/redirect.cgi
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteCond %{HTTP_HOST} ^www.hinduismtoday.org [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
Fabulous. Thank you for your "responsiveness" I mean, you turned this around about as fast as it could be...
Sivakatirswami
I think I have become addicted to Experts Exchange. I signed up last month and never used it until 2 days ago.
I'm glad I could help ya..
I'm glad I could help ya..
ASKER
Yes, EE is marvelous... in fact I would go so far as to say that is a far reaching innovation in human consciousness. I guess that sounds "over the top" but where else to you find 3 million people working together, helping each other?! It's such a breath of fresh air from what we see in the news and compared to what the "greed mongers" of international companies are doing.
and my Tech support at ServePath want to charge a minimum $150.00 for an hour's work to do this mod_rewrite for me... I thought, "That's just mad... let me go to to EE"
I've been with EE for two years. So hopefully it will make a contribution to a new breed, a new generation of people for a better world. There I go again, getting romantic over the wonders of the internet...
Sivakatirswami
and my Tech support at ServePath want to charge a minimum $150.00 for an hour's work to do this mod_rewrite for me... I thought, "That's just mad... let me go to to EE"
I've been with EE for two years. So hopefully it will make a contribution to a new breed, a new generation of people for a better world. There I go again, getting romantic over the wonders of the internet...
Sivakatirswami
ASKER
Oops! I may have to get my points back! (just kidding)
but I'm not getting consistent results from FireFox
http://www.hinduismtoday.org/archives/2006/1-3/
should rewrite to
http://www.hinduismtoday.com/archives/2006/1-3/
but, it is not
http://www.hinduismtoday.org/ works fine --> http://www.hinduismtoday.com/index.shtml is served
Also for now for some wierd reason
http://www.hinduism-today.org/past_issues.shtml
gives me "Server Not Found"
So there must be some RegEx missing here:
errorDocument 404 /cgi-bin/redirect.cgi
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteCond %{HTTP_HOST} ^www.hinduismtoday.org [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
but I'm not getting consistent results from FireFox
http://www.hinduismtoday.org/archives/2006/1-3/
should rewrite to
http://www.hinduismtoday.com/archives/2006/1-3/
but, it is not
http://www.hinduismtoday.org/ works fine --> http://www.hinduismtoday.com/index.shtml is served
Also for now for some wierd reason
http://www.hinduism-today.org/past_issues.shtml
gives me "Server Not Found"
So there must be some RegEx missing here:
errorDocument 404 /cgi-bin/redirect.cgi
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.hinduism-today.com [NC]
RewriteCond %{HTTP_HOST} ^www.hinduismtoday.org [NC]
RewriteRule ^(.*)$ http://www.hinduismtoday.com/$1 [R=301,L]
Your right, it is nice to see people working together for once rather than just trying to extort outrageous amounts of money out of people to do simple little things where if they company who is doing the systems administration doesn't know what they are doing they will come here and ask questions and still charge you $150 an hour for the answers they got for free from here. :/
Well, I checked into the problems you were having and found a solution which will fix it.
I just did a test and if you have...
RewriteCond ...
RewriteCond ...
RewriteRule ...
It does not work, BUT, if you have...
RewriteCond ...
RewriteRule ...
RewriteCond ...
RewriteRule ...
It works fine. I guess what you will need to do is setup a RewriteCond and RewriteRule for every domain you need to forward. I know it's alot of conditions and rules but it still doesn't cause any performance issues it just makes the .htaccess file big. :/
Hmm... As far as the www.hinduism-today.org it is giving me DNS issues, it seems like there are no records for it...
Server: boston2-qwest.bellatlantic .net
Address: 151.203.0.85
*** boston2-qwest.bellatlantic .net can't find www.hinduism-today.org: Non-existent domain
root@simba [~]# nslookup www.hinduism-today.org
Server: 216.240.142.170
Address: 216.240.142.170#53
** server can't find www.hinduism-today.org: NXDOMAIN
That's the same response from 2 different DNS servers. I'm not even showing that the .org domain is a registered domain, are you positive that it's actually registered?
root@simba [~]# whois hinduism-today.org
NOT FOUND
Well, I checked into the problems you were having and found a solution which will fix it.
I just did a test and if you have...
RewriteCond ...
RewriteCond ...
RewriteRule ...
It does not work, BUT, if you have...
RewriteCond ...
RewriteRule ...
RewriteCond ...
RewriteRule ...
It works fine. I guess what you will need to do is setup a RewriteCond and RewriteRule for every domain you need to forward. I know it's alot of conditions and rules but it still doesn't cause any performance issues it just makes the .htaccess file big. :/
Hmm... As far as the www.hinduism-today.org it is giving me DNS issues, it seems like there are no records for it...
Server: boston2-qwest.bellatlantic
Address: 151.203.0.85
*** boston2-qwest.bellatlantic
root@simba [~]# nslookup www.hinduism-today.org
Server: 216.240.142.170
Address: 216.240.142.170#53
** server can't find www.hinduism-today.org: NXDOMAIN
That's the same response from 2 different DNS servers. I'm not even showing that the .org domain is a registered domain, are you positive that it's actually registered?
root@simba [~]# whois hinduism-today.org
NOT FOUND
ASKER
OK Thanks... I will write explicit rules for each domain. extra lines... no big deal.
Right, DNS issues. Yesterday I also got a couple or resolution failures, don't know why... hinduism-today definitely is registered... Not sure why it is not propagated... I'll check the zone records carefully. thanks for the heads up. Strange you get a blank from your side....
From here I get:
[kt-enet:~] katir% whois hinduism-today.com
[SNIP all the verbiage to:]
http://www.networksolutions.com
Registrant:
Himalayan Academy
107 Kaholalele Road
Kapaa, HI 11111
US
Domain Name: HINDUISM-TODAY.COM
Administrative Contact, Technical Contact:
Japendra Mahesvaran japendra@hindu.org
107 Kaholalele Road
Kapaa, HI 11111
US
808-822-7032 fax: 808-822-4351
Record expires on 28-Mar-2009.
Record created on 28-Mar-1999.
Database last updated on 1-Jul-2006 15:05:19 EDT.
Domain servers in listed order:
NS19.ZONEEDIT.COM 69.10.134.196
NS8.ZONEEDIT.COM
Right, DNS issues. Yesterday I also got a couple or resolution failures, don't know why... hinduism-today definitely is registered... Not sure why it is not propagated... I'll check the zone records carefully. thanks for the heads up. Strange you get a blank from your side....
From here I get:
[kt-enet:~] katir% whois hinduism-today.com
[SNIP all the verbiage to:]
http://www.networksolutions.com
Registrant:
Himalayan Academy
107 Kaholalele Road
Kapaa, HI 11111
US
Domain Name: HINDUISM-TODAY.COM
Administrative Contact, Technical Contact:
Japendra Mahesvaran japendra@hindu.org
107 Kaholalele Road
Kapaa, HI 11111
US
808-822-7032 fax: 808-822-4351
Record expires on 28-Mar-2009.
Record created on 28-Mar-1999.
Database last updated on 1-Jul-2006 15:05:19 EDT.
Domain servers in listed order:
NS19.ZONEEDIT.COM 69.10.134.196
NS8.ZONEEDIT.COM
http://www.ilovejackdaniels.com/apache/mod_rewrite-cheat-sheet/
I will see what I can come up with to do what you want.