Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何使用多个查询参数重定向动态子域_.htaccess - Fatal编程技术网

.htaccess 如何使用多个查询参数重定向动态子域

.htaccess 如何使用多个查询参数重定向动态子域,.htaccess,.htaccess,我想重定向 domain.com/test.php?username=username&code1=849&code2=4d1 username.domain.com/849/4d1 到 使用.htaccess 目前我有 RewriteRule ^test/([^/]+)/([^/]+)/([^/]+) test.php?username=$1&code1=$2&code2=$3 [NC] RewriteCond %{HTTP_HOST} ^(^.*)\.do

我想重定向

domain.com/test.php?username=username&code1=849&code2=4d1
username.domain.com/849/4d1

使用.htaccess

目前我有

RewriteRule ^test/([^/]+)/([^/]+)/([^/]+) test.php?username=$1&code1=$2&code2=$3 [NC]
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*) test.php?username=%1&code1=%2&code2=%3 [NC]
重定向可以工作,但代码(php)

是空的。谁能给我指出正确的方向吗

谢谢你找到了

所以如果你想重定向

domain.com/test.php?username=username&code1=849&code2=4d1
username.domain.com/849/4d1

您需要将以下代码添加到.htaccess文件中:

RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*)/([^/]+) test.php?username=%1&code1=$1&code2=$2 [NC]
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*)/([^/]+) test.php?username=%1&code1=$1&code2=$2 [NC]