DNS/.htaccess files to redirect subdomain to specific folder

江枫思渺然 提交于 2019-12-12 03:54:00

问题


I'm trying to redirect my subdomain to a flder. I think I have the .htaccess code from another post here. Something like:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^clients\.example\.com$
RewriteRule ^ http://example.com/clients/root/app%{REQUEST_URI} [L,P]

What DNS settings should I set up for the clients. subdomain to tie it in with the .htaccess.


回答1:


You need to create a CNAME to point clients.example.com to the same server as example.com. Then you need to make sure your webserver is setup to serve the clients.example.com in the same root as example.com.

Of, you can simply setup clients.example.com's vhost to point to the /clients/root/app/ folder instead. There's a directive called DocumentRoot that you'd use to point a vhost to a where it's root folder is.

In the case of the first instance, where both the main domain and subdomain point to the same root, you don't need to use the P flag:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^clients\.example\.com$
RewriteRule ^ /clients/root/app%{REQUEST_URI} [L]

Is good enough and circumvents the need to go through mod_proxy.



来源:https://stackoverflow.com/questions/18874085/dns-htaccess-files-to-redirect-subdomain-to-specific-folder

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