Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.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
Regex 使用.htaccess将路径从主域重定向到子域-多站点安装_Regex_Apache_.htaccess_Mod Rewrite_Drupal - Fatal编程技术网

Regex 使用.htaccess将路径从主域重定向到子域-多站点安装

Regex 使用.htaccess将路径从主域重定向到子域-多站点安装,regex,apache,.htaccess,mod-rewrite,drupal,Regex,Apache,.htaccess,Mod Rewrite,Drupal,我在www.my-main-domain.com上安装了drupal, 我在subdomain.my-main-domain.com上安装了drupal multisite 我想重定向所有: www.my-main-domain.com/user,www.my-main-domain.com/users, www.my-main-domain.com/user/* 我的子域子域的路径: my-main-domain.com/user,subdomain.my-main-domain.com/us

我在www.my-main-domain.com上安装了drupal, 我在subdomain.my-main-domain.com上安装了drupal multisite

我想重定向所有:

www.my-main-domain.com/user,www.my-main-domain.com/users, www.my-main-domain.com/user/*

我的子域子域的路径:

my-main-domain.com/user,subdomain.my-main-domain.com/users, subdomain.my-main-domain.com/*

分别

我正在.htaccess文件中写入以下内容:

RewriteBase / 
RedirectMatch 301 ^/users/(.*)$ http://subdomain.my-main-domain.com/users/$1
RedirectMatch 301 ^/user/(.*)$ http://subdomain.my-main-domain.com/user/$1
RedirectMatch 301 ^/users$ http://subdomain.my-main-domain.com/users
RedirectMatch 301 ^/user$ http://subdomain.my-main-domain.com/user
但它重定向到子域,但在循环中继续,因此以空白显示结束

请注意,它是使用公共根.htaccess文件的多站点安装。 我已经尝试了路径重定向drupal模块,但它不支持内部路径重定向,因为路径已经在使用中


请帮忙。谢谢

使用
mod_rewrite
来控制处于重写状态的主机名

RewriteEngine On

RewriteCond %{HTTP_HOST} ^my-main-domain\.com$ [NC]
RewriteRule ^(users?)(/.*)?$ http://subdomain.my-main-domain.com/$1$2 [L,R=301,NC]

PS:还请注意,您的4条规则可以组合成一条,如上所示。

唯一一件事我不知道它如何处理/user的重定向,其中我们只匹配上述规则中的/user。你能解释一下吗?事实上,我使用regex
users在
/user
之后做了
s
可选?
这就是为什么它同时匹配
/user
/users