【问题标题】:Use mod_rewrite to take part of the subdomain and append it to the url使用 mod_rewrite 获取子域的一部分并将其附加到 url
【发布时间】:2012-10-15 13:57:08
【问题描述】:

是否可以使用 mod_rewrite 从 url 中取出部分子域并将其附加到 url 中?

这是当前的 url,我为每个客户设置了多个子域:

customername.subdomain.domain.co.uk

我将指向一个新服务器和新站点。新的url格式为:

http://domain/login/customername

因为所有客户现在都在一个站点下。

所以我想做的是使用 mod_rewrite 将.subdomain 之前的任何内容放在https://domain/login/customername 的末尾

这是我目前得到的:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).subdomain.domain(.*)$ [NC] 
RewriteCond %{REQUEST_URI} $1/   
RewriteRule ^(.*)$ https://domain/login/$1 [L]

【问题讨论】:

    标签: regex .htaccess mod-rewrite


    【解决方案1】:
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).subdomain.domain(.*)$ [NC] 
    RewriteRule .* https://domain/login/%1 [L]
    

    诀窍是: %1 匹配 $1 从上一行... p>

    【讨论】:

    • 最好能解释一下不同之处和原因。
    • 别告诉我...我知道这些东西。 :) 将其添加到答案中。
    猜你喜欢
    • 2012-01-22
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2012-01-27
    • 2020-11-22
    相关资源
    最近更新 更多