【问题标题】:.htaccess redirect subdomain to a subdirectory.htaccess 将子域重定向到子目录
【发布时间】:2018-06-22 16:44:24
【问题描述】:

我正在开发一个网站,用户在该网站上注册他们的一些个人数据。他们每个人都获得了他们个人资料的唯一 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

我对其他页面有一些其他重定向规则,例如 登录、注册 等 有什么办法吗?

现场示例 - https://john.sarahah.comhttps://emma.sarahah.com

【问题讨论】:

    标签: .htaccess url-rewriting subdomain


    【解决方案1】:

    重写规则使用正则表达式,让你拥有全部权力:

    RewriteEngine on
    
    RewriteMap    lowercase int:tolower
    
    RewriteCond   "${lowercase:%{HTTP_HOST}}"   "^([^.]+)\.example\.com$"
    RewriteRule   "^(.*)" "https://example.com/user.php?username=%1;path=$1" [R,L]
    

    这几乎是https://httpd.apache.org/docs/2.4/rewrite/vhosts.html的第一个例子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-28
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 2012-09-07
      • 2016-09-24
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多