Im using Apache as well as an .htaccess file to setup some redirects. It is possible to method to 301 redirect my way through a website to some subdomain except for that domain index?

So redirect http://domain.com/* to http://sub.domain.com/*

But leave http://domain.com/ where it's?

Thanks ahead of time if anybody has the capacity to help!

Single rewrite rule:

# Rewrite if on main domain AND NOT requesting index
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC]
RewriteCond %{REQUEST_URI} !^(/(index[.](html|php))?)?$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L]
# Check for non-empty request URI
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .* http://sub.domain.com%1 [L,R=301]

You most likely wish to permit default html or php in your primary domain. For the reason that situation, the next set of rules should work. Make sure confirm.

# Skip the rewrite for the root of domain.com
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC]
RewriteCond %{REQUEST_URI} ^(/(index[.](html|php))?)?$
RewriteRule ^(.*)$ - [L]

# Rewrite everything else 
RewriteCond %{HTTP_HOST} ^(domain[.]com)$ [NC]
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L]