Regex htaccess从文件夹重定向

Regex htaccess从文件夹重定向,regex,apache,.htaccess,mod-rewrite,proxy,Regex,Apache,.htaccess,Mod Rewrite,Proxy,我试图用一个url来表达这一点: http://foo.domain.com/bar/fee/ 为此: http://IP:port/bar/fee/ 这是我当前的代码: RewriteEngine on RewriteCond %{HTTP_HOST} ^foo.domain.com/ RewriteRule ^(.*) http://IP:port/$1 [P] 但这不起作用,因此出现了这个问题。您无法在HTTP\u HOST变量中匹配路径段 使用此规则: RewriteEngine

我试图用一个url来表达这一点:

http://foo.domain.com/bar/fee/
为此:

http://IP:port/bar/fee/
这是我当前的代码:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^foo.domain.com/
RewriteRule ^(.*) http://IP:port/$1 [P]

但这不起作用,因此出现了这个问题。

您无法在
HTTP\u HOST
变量中匹配
路径段

使用此规则:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^foo\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://IP:port/$1 [P]
如果不需要代理功能,请更换
p
标志:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^foo\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://IP:port/$1 [L,R=301,NE]

您不能在
HTTP\u主机
变量中匹配
路径段

使用此规则:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^foo\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://IP:port/$1 [P]
如果不需要代理功能,请更换
p
标志:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^foo\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://IP:port/$1 [L,R=301,NE]

只需将我推到我的常规域。再次编辑后,我建议使用第二条规则
R=301
我仍然没有成功。我正在我的站点上使用cloudflare,这会有影响吗?或者我的设置中可能遗漏了什么?您是否使用了规则的第二个版本?你在这个.htaccess文件中还有其他的规则吗?或者还有其他的.htaccess文件吗?在我的.htaccess文件中只有一个东西,那就是
DirectoryIndex.html index.php
,因为我以前对此有一些问题,是的,我正在使用第二个规则,只是把我推到我的常规域。再次编辑,我建议对
R=301使用第二条规则,我仍然没有成功。我正在我的站点上使用cloudflare,这会有影响吗?或者我的设置中可能遗漏了什么?您是否使用了规则的第二个版本?你在这个.htaccess文件中还有其他规则吗?或者还有其他的.htaccess文件吗?在我的.htaccess文件中只有一个规则,那就是
DirectoryIndex.html index.php
,因为我以前遇到过一些问题,是的,我正在使用第二个规则