Forum Moderators: phranque
I am trying to write some mod rewrites that would:
direct:
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]
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
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.
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