首页 > 解决方案 > 使用 htaccess 将文件夹重写为子域

问题描述

我想在此之后重写所有地址

http://example.com/users/*

对此

http://*.example.com/

例如:

http://example.com/users/admin

http://admin.example.com/

我想在 .htaccess 文件中执行此操作。

我现在有这个,但它不起作用:

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

谁能帮我?谢谢

标签: .htaccessmod-rewrite

解决方案


删除 中域之前的点RewriteCond

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

您的规则失败,因为您正在检查http://example.com,而不是匹配起始点。


推荐阅读