【问题标题】:htaccess redirect from folderhtaccess 从文件夹重定向
【发布时间】:2013-11-13 17:04:08
【问题描述】:

我正在尝试编写一个看起来与此类似的网址:

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]

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

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite proxy


    【解决方案1】:

    您不能在 HTTP_HOST 变量中匹配 path segment

    使用这条规则:

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

    如果您不想要 proxy 功能,请替换 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 index.html index.php,因为我之前遇到过一些问题,是的,我使用的是第二条规则
    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 2014-10-20
    相关资源
    最近更新 更多