【问题标题】:htaccess not working properly for sub url having more slasheshtaccess 对于具有更多斜杠的子 url 无法正常工作
【发布时间】:2017-05-02 04:27:59
【问题描述】:

我有 2 个网站。称之为 5p_front (http://localhost/5p_front/)(在 OctoberCMS 中开发)和 5p_group (http://localhost/5p_group/)(在 CakePHP 中开发强>)

5p_front 我有一个 .htaccess 文件,我在其中设置了一个条件,一旦找到就会重定向到 5p_group 网站url 中有 5p_group_login 的单词。下面是代码

.htaccess

RewriteRule ^5p_group_login.*$ http://localhost/5p_group [L,R=301]

因此,如果有人试图去这里例如 http://localhost/5p_front/5p_group_login ,他们将被简单地重定向到这里 http://localhost/5p_group/

这适用于主页和其他子页面,例如关于页面,例如 http://localhost/5p_front/we-are-5p-group

但是我有一个产品内页http://localhost/5p_front/product/10,如果我悬停允许我重定向到登录页面的菜单项,它会显示此 URL http://localhost/5p_front/product/5p_group_login,因此当我点击它时,我无法重定向在http://localhost/5p_group/,因为它仅在http://localhost/5p_front/product/5p_group_login 上转发到此当前网址,这不应该是这种情况。

此外,我的菜单是动态的,我使用Static Pages 插件创建了 OctoberCMS 提供的菜单,并且我创建了如下所示的“登录”菜单链接。

即使用户位于http://localhost/5p_front/product/10 并单击显示http://localhost/5p_front/product/5p_group_login 的“登录”链接,如果我将鼠标悬停在其上,我如何将URL 重定向到http://localhost/5p_group/

有人可以在这里指导我在这种情况下我应该怎么做。

谢谢

【问题讨论】:

    标签: .htaccess octobercms


    【解决方案1】:

    你的规则

    RewriteRule ^5p_group_login.*$ http://localhost/5p_group [L,R=301]
    

    当放置在5p_front/.htaccess 中时,只会影响以/5p_front/5p_group_login 开头的URI(因为您的模式中的前导^)所以/5p_front/product/5p_group_login 将不匹配。

    如果你想重写包含5p_group_login anyhwere 的 URL,只需使用:

    RewriteRule 5p_group_login http://localhost/5p_group [L,R=301]
    

    【讨论】:

    • 哇.. 很好的解释。谢谢。
    猜你喜欢
    • 2015-07-23
    • 2016-04-21
    • 2020-05-12
    • 2011-09-19
    • 2017-08-08
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多