【问题标题】:Redirect > from subfolder to its main folder重定向 > 从子文件夹到其主文件夹
【发布时间】:2014-08-16 05:21:46
【问题描述】:

我想将 403 页面(子文件夹/)(选项 -Indexes)重定向到其主/上文件夹。

示例原始网址>

example.com/photos/artist/name/events.html(“name”文件夹包含许多“events”html文件)

但访客不知何故登陆>

example.com/photos/artist/name/events/

我可以在 .htaccess 中添加以下行 ..

Redirect /photos/artist/name/events/ http://example.com/photos/artist/name/events.html

但问题是 /name/* 中有许多事件 html 文件,它不仅适用于该目录,还适用于其他 /artist/name1 、 /artist/name2 等

/artist
   /name1
      /events1, 2, 3,.. .html
   /name2
      /events1, 2, 3,.. .html

我想喜欢..当访客登陆时

example.com/photos/artist/name/events/> 这个需要重定向到

example.com/photos/artist/name/

这可能吗?

我在下面尝试过,403 最终出现内部错误..

Redirect /photos/artist/*/*/ /photos/artist/*/

我不是这个领域的专家,所以希望我的问题可以理解..

谢谢。

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    您需要为此使用正则表达式。假设您仍想使用 mod_alias,而不是 mod_rewrite,例如,您需要使用 RedirectMatch 而不是 Redirect。对于像example.com/photos/artist/phil-collins/events/ 这样的网址,您需要以下指令:

    RedirectMatch temp /photos/artist/([^/]+)/events/ http://example.com/photos/artist/$1/
    

    【讨论】:

    • 伙伴,成功了!!我在 .htaccess > RedirectMatch temp /photos/artist/([^/]+)/([^/]+)/ http://example.com/photos/artist/$1/ ([^/]+)/([^/]+)
    • 虽然不知道你所说的 mod_alias 是什么意思.. 我是这方面的新手:/
    • 如果 url 以没有“/”结尾 http://example.com/photos/artist/name/event/ > 似乎不起作用 http://example.com/photos/artist/name/event > 404 错误可以解决这个问题吗?
    • 在网址末尾使用/?,而不是/
    猜你喜欢
    • 1970-01-01
    • 2021-09-08
    • 2014-04-03
    • 1970-01-01
    • 2021-07-09
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    相关资源
    最近更新 更多