Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite. what's wrong with mine?

kind of works.. but not for everything

         

schulerlab

4:46 am on Jan 31, 2008 (gmt 0)

10+ Year Member



I have a website www.example.com with one subdomain aaa

I am trying to write some mod rewrites that would:

direct:

  1. exampl.com ===> www.example.com
  2. aaa.example.com ===> aaa.example.com (leave it alone)
  3. xyz.example.com ===> www.example.com (any other subdomains should be redirected to www)

my code works for 1. and 2., but not for 3. if a person types in xyz.example.com, they get an error saying xyz.example.com - server not found.

here is the code:
------------------------
RewriteEngine on
#
# Redirect all other non-blank non-www domains (or aaa subdomain) to www domain
rewritecond %{HTTP_HOST} .
rewritecond %{HTTP_HOST}!^(www¦aaa)\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
--------------------------

what am I doing wrong? :(

thanks for any help in this matter.

[edited by: tedster at 6:29 am (utc) on Jan. 31, 2008]
[edit reason] switch to example.com in code - it can never be owned [/edit]

jdMorgan

7:52 pm on Jan 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"Server not found" indicates that you have not set up DNS for your subdomain(s), so your browser cannot find the IP address for your subdomain(s) in the DNS system, and so it cannot connect to your server. You'll need to edit your DNS zone file to add specific or wild-card A record(s) or CNAME(s) for your subdomain(s).

Also be aware that if you're on named-based virtual (shared) hosting, your server must also be configured to accept requests for subdomains; Some hosts support it freely, others want to charge you for it, and others don't support/allow it at all.

Jim

schulerlab

3:11 am on Feb 1, 2008 (gmt 0)

10+ Year Member



so, if a person mistypes www.example.com, and instead types wwq.example.com , there is no way to redirect it to www.example.com ?

I am on a shared hosting, and they have cpanel set up to create subdomains. so, I had no trouble creating the legit subdomain aaa.example.com. and that redirects fine.

but.. you are saying the way it works, I can't redirect typos (in the subdomain) to www.example.com?

thanks.

jdMorgan

4:03 am on Feb 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, if the requested domain or subdomain is not defined in DNS, then the request cannot be delivered to a server. And if it isn't delivered to a server, then it cannot be redirected. The "server not found" message indicates an error at the browser level -- It is reporting that it cannot get the IP address from the DNS system that is required to deliver the HTTP request to a server. This may be just another example of the high cost of inexpensive hosting.

The better hosting accounts can be set up to define wild-card subdomains, and point all of them to the same directory space, so you can then use mod_rewrite to sort them all out (if desired) into one or more separate (sub)directories. Or you can redirect any or all of them as desired.

With this sort of setup, DNS configuration is usually done separately, not with one all-encompassing control panel. For example, none of the hosts I use even have what you would call a control panel. But then, I prefer to do things manually, giving up convenience for greatly-increased control. I'm not sure it's a 'rule' but I've found that having this level of control is strongly correlated with the option of having your own unique IP address. Such hosting options are readily available at reasonable cost, although not typically at the $3.99/month level.

Jim

schulerlab

5:27 am on Feb 1, 2008 (gmt 0)

10+ Year Member



ok.. got it. makes sense now. :)

thanks for explaining. I do appreciate it.