Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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
Mod rewrite 重写引擎:如何将子域重写到index.php?_Mod Rewrite_Subdomain - Fatal编程技术网

Mod rewrite 重写引擎:如何将子域重写到index.php?

Mod rewrite 重写引擎:如何将子域重写到index.php?,mod-rewrite,subdomain,Mod Rewrite,Subdomain,几天后,我询问了将动态目录重定向到index.php的问题,我得到了这段完美的代码(这是我在.htaccess中仅有的代码): 这会将类似的URL转换为 现在我想把像这样的子域翻译成 从我在Internet上找到的示例中,我尝试添加以下行: RewriteRule ^(.*)\.mydomain\.example index.php?dir=$1 但它不起作用。我没有足够的mod rewrite经验来判断遗漏了什么或错了什么。您能帮我找到一种方法来保持动态目录转换,并添加catch-all子域

几天后,我询问了将动态目录重定向到index.php的问题,我得到了这段完美的代码(这是我在.htaccess中仅有的代码):

这会将类似的URL转换为

现在我想把像这样的子域翻译成

从我在Internet上找到的示例中,我尝试添加以下行:

RewriteRule ^(.*)\.mydomain\.example index.php?dir=$1
但它不起作用。我没有足够的mod rewrite经验来判断遗漏了什么或错了什么。您能帮我找到一种方法来保持动态目录转换,并添加catch-all子域规则吗


问候

mod_重写规则使用相对于虚拟主机的请求路径。尝试为每个虚拟主机使用不同的重写规则,但将其文档放在同一目录中。

使用只能测试。对于主机名,您需要在以下位置使用
%{HTTP\u host}

RewriteRule ^(.*)\.mydomain\.example index.php?dir=$1
RewriteCond %{HTTP_HOST} ^(.+)\.example\.example$
RewriteRule ^ index.php?dir=%1