2

I am working on a site making my subdir to appear as root just like //example.com/ is //example.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.example.com| which is//example.com/subdir/adminmy.htaccessredirects me to the main domain//example.com`

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

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

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

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

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

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

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

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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