且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从子目录子域的Apache URL重写

更新时间:2023-02-24 09:47:27

 的RewriteCond%{HTTP_HOST}域\\ .COM [NC]
重写规则^ /([A-ZA-Z0-9 - ] +)/ $ HTTP(*)://$1.domain.com/$2 [L,R]

Can you suggest a set of Apache rewrite rules to convert domain.com/app to app.domain.com? The rewrite rules should be valid for any app name and any sub path specified. For example, the script should be able to convert domain.com/otherapp/view.do to otherapp.domain.com/view.do in a generic fashion. Much appreciate.

RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteRule ^/([A-Za-z0-9-]+)/(.*)$ http://$1.domain.com/$2 [L,R]