i am attempting to do an apache rewrite where when the term "admin" is included in the request_uri

mydomain.com/admin/anything_else

re-write the host to utilize a subdomain

admin.mydomain.com/admin/anything_else.

likewise, basically click a hyperlink whilst in the admin.mydomain.com which is a url WITHOUT "admin" inside it, then i must rewrite the url to

mydomain.com/anything_else

My real question is. can regex do an exist check like this? I am aware that it may do terms not matching (I'm not sure the syntax though...), however in this situation I would like regex to fail completely. Any ideas?

ReWriteCond [^(admin)]$

mydomain.com/admin/hi - matches mydomain.com/anything - does not match

You might use negative lookaheads, like mydomain.com/(?!admin)

Try these rules:

RewriteCond %{HTTP_HOST} !=admin.example.com
RewriteRule ^admin(/|$) http://admin.example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} =admin.example.com
RewriteRule !^admin(/|$) http://example.com%{REQUEST_URI} [L,R=301]

I wound up doing such like...

# Redirect to subdomain admin for an admin specific uri request
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} admin
RewriteRule ^(.*)$ http://admin.example.com$1 [L]

# Redirect to subdomain admin for an admin specific uri request
RewriteCond %{HTTP_HOST} ^admin.example.com$
RewriteCond %{REQUEST_URI} !admin 
RewriteRule ^(.*)$ http://www.example.com$1 [L]