I've been looking over the same .htaccess codes that will not work for a subdomain. It seems not many people really know how to do a correct .htaccess (including me I suppose). I've tried:

RewriteCond %{HTTP_HOST} !^site\.net$ [NC]
RewriteRule ^(.*)$ http://site.net/$1 [R=301,L]

And it requires the WWW on the subdomain, such as bob.site.net, which I do not want. Does anyone have a solution to my problem?

Recommended Answers

All 2 Replies

So, basically starting off reading your rule, it says:
If someone accesses this site that is *NOT* from http://site.net
Then redirect them to http://site.net/string

Maybe removing the 'NOT' is what your looking for:

RewriteCond %{HTTP_HOST} ^site\.net$ [NC]
RewriteRule ^(.*)$ http://www.site.net/$1 [R=301,L]

Which would state, if someone is accessing your site from site.net redirect to www.site.net/string

This rule would activate for anyone hitting http://site.net but not http://bob.site.net

Is this the goal?

Yes, that worked. Thanks mate! Its so difficult finding any good information about htaccess. It seems no one really knows it well enough.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.