An example would be:
RewriteCond %{HTTP_HOST}
!(^sub1\.domain\.com$)|(sub2\.domain\.com$)|(^(sub3\.domain\.com$)|(^sub4\.domain\.com$)
[NC]
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]
So as long as your wildcard DNS entry is setup so everything gets sent to your
server, everything besides sub{1..4}.domain.com will be rewritten to
www.domain.com. If you are wondering about SSL, unless you have a wildcard SSL
cert then you should rewrite all SSL requests to www.domain.com anyways.
Also, I strongly recommend not putting these rewrites in an .htaccess file, put
them in your conf file. .htaccess will hinder performance because it's
reloaded on every single request, the rules from the conf file will only be
used on the initial session start. The performance hit is minimal, but get
enough rules and/or a busy enough site and you will surely see the performance
hit.
On Jan 19, 2011, at 10:35 AM, Chad Sollis wrote:
> using everydns, is that possible?
>
> I like that route, however, I also like being able to control it on the
> server so I do not have to update every domain in dns.
>
> (although I am curious if everydns can do that)
>
> ~Chad
>
>
> On Jan 19, 2011, at 10:31 AM, <[email protected]> wrote:
>
>> Why not just use DNS? instead of mod rewrite? Sorry if I missed
>> previous info.
>>
>> Trevyn
>>
>> On Wed, 19 Jan 2011 10:24:00 -0700, Chad Sollis <[email protected]>
>> wrote:
>>> Thanks Brian,
>>>
>>> sorry for not being totally clear. What I want it to do is actually
>>> anything without a subdomain, to redirect to www.domain.com if it has
>>> a subdomain, it will be ignored. Good catch on the QSA.
>>>
>>> how would you change the rule to match according to that objective?
>>>
>>> thanks
>>>
>>> ~Chad
>>>
>>>
>>> On Jan 19, 2011, at 1:00 AM, Bryan Petty wrote:
>>>
>>>> On Tue, Jan 18, 2011 at 2:19 PM, Chad Sollis <[email protected]> wrote:
>>>>> Hey there... to the tune of Wade's request yesterday, trying to make that
>>>>> a wildcard option, can anyone provide some insight, its not redirecting
>>>>> as desired :)
>>>>>
>>>>> RewriteCond %{HTTP_HOST}
>>>>> ^((?!\.).)*\.(com|net|org|ws|biz|ws|us|info|mobi|me)$ [NC]
>>>>> RewriteRule ^(.*)$ http://www.%1.%2/$1 [L,R=301]
>>>>
>>>> Are you really just trying to match _ANYTHING_ that doesn't have "www"
>>>> and redirect it to the "www" equivalent? That's what it looks like,
>>>> and you didn't explain how you want it to work.
>>>>
>>>> This seems like a really bad architectural decision if that's the
>>>> case, but if that's what you're going for, just check if it has the
>>>> "www" prefix, and if it doesn't, then redirect. Then, since you're
>>>> working towards such a wide matching constraint, you might as well
>>>> make sure it handles SSL and also query strings too, like so:
>>>>
>>>> RewriteCond %{HTTPS} =off
>>>> RewriteCond %{HTTP_HOST} !^www\. [NC]
>>>> RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301,QSA]
>>>> RewriteCond %{HTTPS} =on
>>>> RewriteCond %{HTTP_HOST} !^www\. [NC]
>>>> RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301,QSA]
>>>>
>>>> Regards,
>>>> Bryan Petty
>>>
>>>
>>> _______________________________________________
>>>
>>> UPHPU mailing list
>>> [email protected]
>>> http://uphpu.org/mailman/listinfo/uphpu
>>> IRC: #uphpu on irc.freenode.net
>>
>
>
> _______________________________________________
>
> UPHPU mailing list
> [email protected]
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
_______________________________________________
UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net