我正在开发一个网站,用户可以在其中注册一些个人数据。他们每个人都有一个指向其个人资料的唯一URL(请参见下面的示例)。 有什么方法可以使用htaccess重写规则为每个用户获取唯一的URL(如子域)吗?
示例
For John - john.example.com > example.com/user.php?username=john
For Emma - emma.example.com > example.com/user.php?username=emma
对于其他页面,例如 登录,注册 等,我还有一些其他重定向规则 有什么办法吗?
答案 0 :(得分:0)
重写规则使用正则表达式,因此您具有完整的功能:
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond "${lowercase:%{HTTP_HOST}}" "^([^.]+)\.example\.com$"
RewriteRule "^(.*)" "https://example.com/user.php?username=%1;path=$1" [R,L]
的第一个示例