Rewrite folder to subdomain with htaccess

烈酒焚心 提交于 2019-12-24 11:01:04

问题


I want to rewrite all addresses after this

http://example.com/users/*

to this

http://*.example.com/

for example:

http://example.com/users/admin

http://admin.example.com/

I want to do this in a .htaccess file.

I now have this, but it dont work:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.example\.com$
RewriteRule ^users/([^/]+)/?$ http://$1.example.com/ [NC,R=301,L]

Can anyone help me? Thanks


回答1:


Remove the dot before the domain in the RewriteCond:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^users/([^/]+)/?$ http://$1.example.com/ [NC,R=301,L]

Your rule is failing because you are checking against http://example.com, not matching the starting dot.



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

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