【问题标题】:How to redirect to a dynamic URL with apache mode_rewrite rules (not the classic redirection)?如何使用 apache mod_rewrite 规则重定向到动态 URL(不是经典重定向)?
【发布时间】:2020-01-22 16:50:19
【问题描述】:

我想使用 apache mod_rewrite 规则重定向到动态 URL,而不更改 URL 本身。

动态网址www.example.com/business/carwash

在上面的 url 中,'carwash' 部分是一个用户名,用于查找特定业务。 我想要这样的网址:carwash.example.com 被重定向以显示此 URL 的内容:www.example.com/business/carwash 不更改 URL(URL 仍然是 carwash.example.com )。

我尝试了以下代码:

RewriteCond %{HTTP_HOST} ^carwash.cityrakhsh.com

重写规则 ^(.*) http://example.com/business/carwash [P]

但它没有工作。 我该怎么做? 提前致谢。

【问题讨论】:

    标签: apache redirect mod-rewrite url-rewriting httpd.conf


    【解决方案1】:

    子域,在本例中为 carwash,可以在重写规则中使用 %1 替换

    RewriteCond %{HTTP_HOST} ^(.*).cityrakhsh.com$
    RewriteRule ^(.*) "http://cityrakhsh.com/business/%1/" [P]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2011-09-08
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      相关资源
      最近更新 更多