u003f
u003f

Reputation: 483

using .htaccess to find subdomain files

I have a site example.com whose files are at /path/to/example/ It has subdomains subdomain.example.com whose files are at /path/to/example/subdomain/ How can I serve these files using .htaccess without redirection?

I tried

RewriteCond %{HTTP_HOST} ^subdomain.example.com
RewriteRule ^(.*)$ http://example.com/subdomain/$1 [L]

but this redirects users to a new page.

I also tried

RewriteCond %{HTTP_HOST} ^subdomain.example.com
RewriteRule ^(.*)$ /subdomain/$1 [L]

but this gives a server error.

Upvotes: 1

Views: 39

Answers (1)

anubhava
anubhava

Reputation: 785098

Try this rule:

RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteRule !^subdomain/ subdomain%{REQUEST_URI} [L,NC]

Upvotes: 1

Related Questions