Rewrite folder to subdomain with .htaccess?

喜你入骨 提交于 2019-12-10 11:55:59

问题


I'm currently building a large scale website that allows each profile page to be it's own unique sub-domain. I was wondering how would I do this using an .htaccess and mod_rewrite?

For example:

Turn this: http://example.com/profile/userid into: http://userid.example.com


回答1:


You can try this, if you are using wildcard DNS:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.example\.com$
RewriteRule ^(.*)$ profile/%1/$1 [QSA]


来源:https://stackoverflow.com/questions/6725973/rewrite-folder-to-subdomain-with-htaccess

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