Can I rewrite from subdomain to folder avoiding redirection?

自闭症网瘾萝莉.ら 提交于 2020-01-06 16:54:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!