Forum Moderators: phranque

Message Too Old, No Replies

Yet another mod rewrite question

         

MamaDawg

5:19 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



I apologize in advance if this is really basic, but I'm having a hard time getting my brain around it ...

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?

jdMorgan

7:17 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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?

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

MamaDawg

12:48 pm on Apr 5, 2006 (gmt 0)

10+ Year Member



With all due respect, I've already gone over the mod-rewrite documentation and I'm no stranger to regular expressions. I've read the charter and I'm not posting because I'm lazy and I totally understand that you all must get tired of endless "how do I remove the trailing slash" or "how do I do redirect everything to www..." type questions which people can practically cut and paste from the Apache docs :) ...

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.

jdMorgan

2:07 pm on Apr 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code you posted above should already do what you say you want -- It redirects *any* subdomain that is not equal to "s.thedomain.com".

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

MamaDawg

3:37 pm on Apr 5, 2006 (gmt 0)

10+ Year Member



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 -

jdMorgan

4:34 pm on Apr 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To be clear, you (almost always) have control over your DNS zone file, and can set up an A record for "*.example.com." It's then up to the server configuration whether requests for subdomains get mapped to your server space.

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