问题
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