【问题标题】:Magento htaccess redirection issueMagento htaccess 重定向问题
【发布时间】:2016-11-06 21:05:08
【问题描述】:

我试图将特定 URL 及其所有子 URL 重定向到特定 URL。使用 301 重定向这工作正常,但浏览器 URL 也显示测试内容。详情请看下文

示例:https://www.mywebsite.com/customer/account/login/referer/* 需要重定向到 https://www.mywebsite.com/customer/account/login/register

我尝试的是:

Options +FollowSymLinks
RewriteEngine on
Redirect 301 /customer/account/login/referer  https://mywebsite.com/customer/account/login/register

htaccess 规则仅适用于这个 URL。如果我输入

https://mywebsite.com/customer/account/login/referer/testing 

这将被重定向到https://mywebsite.com/customer/account/login/register/test

请告诉我如何从重定向的 URL 中修剪另一部分(注册后的 URL 部分/*)。我想要实现的是

https://mywebsite.com/customer/account/login/referer/* [任何 URL 的 AFTER referer/(包括 /referer)都需要重定向到 https://mywebsite.com/customer/account/login/register]。

【问题讨论】:

    标签: php .htaccess magento redirect mod-rewrite


    【解决方案1】:

    这是预期的行为,如Redirect 的文档中所述

    那么任何以 URL-Path 开头的请求都会在目标 URL 的位置向客户端返回一个重定向请求。 匹配的 URL-Path 之外的附加路径信息将附加到目标 URL。

    要将所有以此前缀开头的请求重定向到给定的 URL,您可以使用RedirectMatch,它使用正则表达式而不是 URL 前缀

    RedirectMatch ^/customer/account/login/referer https://mywebsite.com/customer/account/login/register
    

    你不需要使用

    Options +FollowSymLinks
    RewriteEngine on
    

    因为这是为 mod_rewrite 准备的。 RedirectRedirectMatch 由 mod_alias 模块提供。

    【讨论】:

    • 谢谢奥拉夫。这很好用。正是我想要达到的目标。现在所有 URL 都根据请求进行重定向。也谢谢你的详细解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多