【问题标题】:Subdomain with Query String HTaccess带有查询字符串 HTaccess 的子域
【发布时间】:2016-05-26 02:58:11
【问题描述】:

我有以下htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*).domain\.com
RewriteRule ^(.*)$ index-merchant.php?id=%1 [NC,QSA]

它可以捕获 $_GET['id'] 值,但现在我想在里面添加一些东西

我要抓拍

sub.domain.com/anything1/anylength
sub.domain.com/anything1/anything2/anything3

我想将任何东西 1/任何东西 2/任何东西 3 捕获为 $_GET['query_string']; 查询字符串可以是任何形式的长度,总而言之,如果可能的话,我想将其捕获为通配符 (.*)

如何让我的 .htaccess 能够捕获 $_GET['query_string'] 和 $_GET['id'] 这是我的子域

谢谢!

【问题讨论】:

  • 这实现起来极其简单。你还没试过吗?
  • 我确实尝试过 RewriteRule ^(.*)/(.*)$ index-merchant.php?id=%1&q=%2 [NC,QSA] 但它不起作用

标签: php apache .htaccess mod-rewrite query-string


【解决方案1】:

您不需要使用% 匹配项,因为这些匹配项仅用于RewriteCond 中捕获的组。您需要改用美元符号$,并记住再次从1开始:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*).domain\.com
RewriteRule ^(.*)$ index-merchant.php?id=%1&q=$1 [NC,QSA,L]

现在,对sub.domain.com/anything1/anylength 的请求将重写为/index-merchant.php?id=sub&q=anything1/anylength

此外,添加L 标志(如图所示)以防您决定在此规则下方添加任何其他规则。

【讨论】:

    猜你喜欢
    • 2015-06-13
    • 1970-01-01
    • 2013-03-26
    • 1970-01-01
    • 2013-12-21
    • 2016-01-18
    • 1970-01-01
    • 2020-03-18
    • 2014-07-08
    相关资源
    最近更新 更多