Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am working on a site making my subdir to appear as root just like //domain.com/ is //domain.com/subdir and also access/load files hiding the subdir. My site have this .htaccess(below) and its working. My problem is when I add a subdomain like //admin.domain.com which is //domain.com/subdir/admin my .htaccess redirect me to the main domain //domain.com

Options -Indexes
RewriteEngine on
Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
Options +SymLinksIfOwnerMatch

RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule .* http://domain.com/   [L,R=301]
RewriteRule ^$ domain/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/domain%{REQUEST_URI} -f
RewriteRule .* domain/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* domain/index.php?rp=$0 [QSA]
share|improve this question

1 Answer 1

I think you'll need to do something along these lines:

Options -Indexes
RewriteEngine on
RewriteBase /
Options +FollowSymLinks
Options +SymLinksIfOwnerMatch

#Match admin.domain.com default page
RewriteCond %{HTTP_HOST} ^admin.domain.com$ [NC]
RewriteRule ^$ domain/admin/index.html [L]

#Match files that exist in domain/admin/
RewriteCond %{HTTP_HOST} ^admin.domain.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}domain/admin/%{REQUEST_URI} -f
RewriteRule .* domain/admin/$0 [L]

#Match non-exisiting files in domain/admin
RewriteCond %{HTTP_HOST} !^admin.domain.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* domain/admin/index.html?rp=$0 [QSA]

#Redirect anything that's not domain.com or admin.domain.com to domain.com
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteCond %{HTTP_HOST} !^admin.domain.com$ [NC]
RewriteRule .* http://domain.com/   [L,R=301]
#Match domain.com default page
RewriteRule ^$ domain/index.html [L]

#Match files that exist in domain/
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}domain%{REQUEST_URI} -f
RewriteRule .* domain/$0 [L]

#Match non-exisiting files in domain
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* domain/index.html?rp=$0 [QSA]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.