问题
I want my subdomain to point directly to a folder. That is if an HTTP request is made to apple.example.com, I want the response to be the contents of example.com/apple/index.html, but not a 301 error. Is it possible?
回答1:
Yes, this is exactly the purpose of tools like ISAPI_REWRITE. My hosting company (orcsweb) uses exactly this technique.
-OIsin
回答2:
Yes, but you need to make sure that your server is able to support virtual domains. I don't know enough about this, but the mod_rewrite is possible without redirects.
回答3:
# Internally rewrite <subdomain>.example.com/<URLpath> to example.com/subs/<subdomain/<URLpath>
RewriteCond $1 !^subs/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /subs/%1/$1 [L]
回答4:
You can serve content from any folder or you can send a redirect to the client, but AFAIK you cannot do both at the same time - you cannot serve content and somehow change the url in browser at the same time.
If it would be possible, it would most definitely lead to many security exploits.
来源:https://stackoverflow.com/questions/1555390/can-i-rewrite-from-subdomain-to-folder-avoiding-redirection