htaccess 对于具有更多斜杠的 sub url 无法正常工作

htaccess not working properly for sub url having more slashes

我有 2 个网站。称之为 5p_front (http://localhost/5p_front/) (Developed in OctoberCMS) and 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 , they will simply be redirected to here http://localhost/5p_group/

这在主页和其他子页面(例如关于页面 http://localhost/5p_front/we-are-5p-group )中运行良好。

但是我有一个产品内页http://localhost/5p_front/product/10 and if i hover the menu item which allows me to redirect to login page, it is showing this url http://localhost/5p_front/product/5p_group_login and hence when i click on it, i am unable to redirect at http://localhost/5p_group/ as it is only recirecting to this current url only http://localhost/5p_front/product/5p_group_login,不应该是这样的。

此外,我的菜单是动态的,我使用 Static Pages 插件来创建 OctoberCMS 提供的菜单,我已经创建了 "Login" 菜单 link 如下所示。

如果我将鼠标悬停在 url 上,如何重定向 http://localhost/5p_group/ even if the user is at http://localhost/5p_front/product/10 and clicks on "Login" link which is showing http://localhost/5p_front/product/5p_group_login

谁能指导我在这种情况下我应该怎么做。

谢谢

你的规则

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 的 URL,只需使用:

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