【问题标题】:.htaccess to redirect a long subdomain URL.htaccess 重定向一个长的子域 URL
【发布时间】:2016-09-20 01:51:58
【问题描述】:

由于我的文件结构的设置方式,我有一些我不想在 URL 中显示的文件夹。

我想重定向这个网址:

到这里:

我试过这个:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^portal.domain.com
RewriteRule ^(.*)$ https://portal.domain.com/portal.domain.com/portal/$1 [L,NC]

但我收到“重定向过多”消息。

【问题讨论】:

    标签: .htaccess redirect mod-rewrite subdomain


    【解决方案1】:

    重写规则:RewriteCond %{HTTP_HOST} ^portal.domain.com 太笼统了,那么:

    1) 用户打开https://portal.domain.com/portal.domain.com/portal/test.php

    2) 重写规则匹配并重定向到https://portal.domain.com/test.php

    3) 但是当用户请求页面时https://portal.domain.com/test.php 重写规则再次匹配并将用户重定向到https://portal.domain.com/test.php

    4,5,6,7,8,9.....) 然后用户打开同一个页面,并且 rewrite rlue 在无限循环中一次又一次地匹配。

    解决方案:条件RewriteCond %{HTTP_HOST} ^portal.domain.com 必须不那么通用,而不是计算重定向位置。

    【讨论】:

    • 我的 www.domain.com 子域是 portal.domain.com。该子域的文件夹也称为portal.domain.com,并包含另一个名为“portal”的文件夹。我不知道如何使它不那么通用,因为我无法更改子域的文件夹名称。你能帮忙写一些我可以试试的代码吗?
    猜你喜欢
    • 1970-01-01
    • 2018-07-18
    • 2012-05-08
    • 1970-01-01
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 2019-10-13
    相关资源
    最近更新 更多