Welcome to WebmasterWorld Guest from 35.153.73.72

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 using mod rewrite

     
6:19 pm on Nov 30, 2003 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:12913
votes: 893


A remote link page has mistakenly added an "f" to the "www" part of my site's URL:

h*tp://fwww.my-domain.com/

They have ignored requests to correct it & this page has become popular lately. How can I edit the below code to forward from "fwww" to "www" without changing the existing RewriteCond/RewriteRule?

RewriteCond %{HTTP_HOST} ^w [NC]
RewriteCond %{HTTP_HOST}!^www\.my-domain\.com
RewriteRule ^(.*)$ h*tp://www.my-domain.com/$1 [R=301,L]

Thanks
6:35 pm on Nov 30, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 2, 2002
posts:1167
votes: 0


I'm confuzzled. How can you rewrite a request that is destined to not even reach you in the first instance?
I don't understand how fwww.domain.tld is going to find your server (but then, I'm not exactly the brightest crayon in the box most times.)
6:38 pm on Nov 30, 2003 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:12913
votes: 893


kevinpate - the "www" part just acts as a sub-domain for most Apache configurations.

h*tp://[b]abc[/b].my-domain.com/

also gets users to my site
6:57 pm on Nov 30, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 2, 2002
posts:1167
votes: 0


Thanks for the explanation. I look forward to you getting an answer.

Our info site is set to redirect send all domain.tld requests to www.domain.tld so outta curiosity I tried fwww.domain and abc.domain a moment ago.
I dinna get back our 404 page, only a generic 404 and the 'most recent error' list in our cpanel doesn't indicate the attempts were even made. Hopefully the answer you get will permit me to also capture any wwww's or fwww's or even learn a tad more of my own abc's.

7:10 pm on Nov 30, 2003 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:12913
votes: 893



Hopefully the answer you get will permit me to also capture any wwww's or fwww's or even learn a tad more of my own abc's.

kevinpate - If you are hosted on an Apache server and are not currently receiving these requests, it may be necessary to have it enabled by your admins

I have controls on addresses, other than my "allowed" list, requesting files. Rather than change half a dozen "allowed" conditions around my site, I'm hoping to 301 this one bad URL, but so far my methods have failed.

7:13 pm on Nov 30, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


This is an example of 'wild-card' DNS, where <anything>.example.com gets resolved to the IP address of 'example.com'. Some hosts allow it, and some don't. If they don't you can often add a specific new subdomain by creating a new 'A record' in your DNS zone file. Again, in some cases it's allowed, and in others it's not.

> without changing the existing RewriteCond/RewriteRule?

Your existing code will only allow domain redirects if the requested hostname starts with 'w', so it can't redirect 'fwww'.

You can make a list of the subdomains you don't want to redirect, and then let the rest get redirected:


RewriteCond %{HTTP_HOST} !^developer\.example\.com
RewriteCond %{HTTP_HOST} !^test\.example\.com
RewriteCond %{HTTP_HOST} !^pre_release\.example\.com
RewriteCond %{HTTP_HOST} !^members\.example\.com
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

or alternately:

RewriteCond %{HTTP_HOST} !^(developer¦test¦pre_release¦members¦www)\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Also, you could stack redirects:


RewriteCond %{HTTP_HOST} ^.+www\.example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

The first rule redirects any requests where something has been added to the beginning of "www", while the second one only redirects requests for alternate domain names starting with "www".

Jim

7:26 pm on Nov 30, 2003 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:12913
votes: 893


Thanks Jim, the "stacking" method works well!

<added>
However, looking at my conds/rules it seems I am over-complicating things a bit. Since I do not have any other sub-domains, and I "think" I want "anything" to forward to my real domain, why couldn't I just change this existing code:


RewriteCond %{HTTP_HOST} ^w [NC]
RewriteCond %{HTTP_HOST}!^www\.my-domain\.com
RewriteRule ^(.*)$ h*tp://www.my-domain.com/$1 [R=301,L]

to simply this (without starting anchor):

RewriteRule (.*)$ h*tp://www.my-domain.com/$1 [R=301,L]

What disastrous scenarios might arise that I haven't thought of?
7:43 pm on Nov 30, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


You need the RewriteCond to prevent an endless loop, since it's an external redirect.

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jim
10:48 pm on Nov 30, 2003 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:12913
votes: 893


Thanks Jim for explaining that. I do plan on adding a sub-domain in the future and this info will make for a smooth(er) transition :)