Forum Moderators: phranque
Here's my current working .htaccess (which was set up to send www.s.thedomain.com to s.thedomain.com):
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^s\.thedomain\.com [NC]
RewriteRule ^(.*)$ [s.thedomain.com...] [R=301,L]
Where "s" is a one character subdomain. What I want to do is send anyone who adds a single character before the "s" to be redirected to the subdomain. i.e.:
1s.thedomain.com -> s.thedomain.com
2s.thedomain.com -> s.thedomain.com
Any suggestions for the best way to do this?
The two keys to mod_rewrite are a precise and exhaustive description of what is to be done, and a good grounding in regular expressions.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
I'm comfortable rewriting URL's at the file level, but trying to get this subdomain level redirect to work in conjunction with the www. -> non www redirect is making my head spin and causing me grief - I'm having a major mental block about this!
Any single character? Is it optional, i.e. do you want to do the redirect whether or not the single character is added? Or are you looking for a separate new rule to 'remove' that extra character before invoking the code you've already got?
It's accurate to say I want to remove the extra character prior to invoking what I already have. I still want www.s.thedomain.com to redirect to s.thedomain.com.
Actually there is only one character I would expect people to type before the "s", but a blanket rule covering any character would do the trick.
I'm wondering if this is a DNS problem... Do you have wild-card subdomains defined in your DNS zone file, or is the DNS record specific for "s.thedomain.com."? Is your server configured to recognize these "1s" subdomains and send the requests to your filespace?
Jim
I'm wondering if this is a DNS problem... Do you have wild-card subdomains defined in your DNS zone file, or is the DNS record specific for "s.thedomain.com."? Is your server configured to recognize these "1s" subdomains and send the requests to your filespace?
Hmmm - that must be the problem.
It seems to be specific for "s.thedomain.com" or "www.s.thedomain.com" ("foo.s.thedomain.com" also fails). It's on shared hosting (for now) so I don't have that level of control and was hoping to find a workaround... it's looking less and less likely <sigh> - thanks -
However, since you are apparently already using a non-www subdomain, it's likely that your server *is* set up for wild-card subdomains, unless you made a special arrangement with the hosting company (and that's unlikely on a shared account) specific to "s.example.com."
So, I'd say the odds are good that if you add an A record (or modify the existing one for "s.example.com.") to point "*.example.com." to your server's IP address, this should work. Non-www subdomain support tends to be an all-or-nothing proposition, since those are the two easiest options for hosts.
Note those trailing periods on the DNS zone file domain names -- they are required.
Jim