重定向>从子文件夹到其主文件夹

时间:2014-08-16 05:21:46

标签: .htaccess redirect

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

示例原始网址>

example.com/photos/artist/name/events.html("名称"文件夹包含许多"事件" html文件)

但访客不知何故登陆>

example.com/photos/artist/name/events/<显示403错误,因为"选项 - 索引"在.htaccess中,并且该位置没有索引页。

我可以在.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/<此位置有index.html,因此访问者可以查看事件。

这可能吗?

我尝试了以下行,403结束了内部错误..

Redirect /photos/artist/*/*/ /photos/artist/*/<我知道这对我很愚蠢:/

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

谢谢。

1 个答案:

答案 0 :(得分:0)

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

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