简体   繁体   English

.htaccess redirectMatch除了基本

[英].htaccess redirectMatch except base

I have this redirect working beautifully: 我有这个重定向工作精美:

RedirectMatch 301 ^/stories/(.*)$ /$1

What I need to happen is happening; 我需要发生的事情正在发生; all sub-pages of /stories/ (eg: example.com/stories/my-story/ redirects to example.com/my-story/). / stories /的所有子页面(例如:example.com/stories/my-story/重定向到example.com/my-story/)。 Great. 大。

Now, I need the base url of example.com/story/ to redirect to example.com/blog/ I've tried the following before and after the redirectMatch: 现在,我需要example.com/story/的基本URL来重定向到example.com/blog/。在redirectMatch之前和之后,我都尝试了以下操作:

Redirect 301 /stories/ http://dev.explorersedge.ca/blog/

No go. 不行 Any ideas? 有任何想法吗?

Thanks, Jason 谢谢,杰森

Place the following redirect, acting on exact /stories/ or /stories URLs (not required presence of the / is defined by ? in regexp), 放置以下重定向,对确切的/stories//stories URL起作用(不要求/存在由regexp中的?定义),

RedirectMacth 301 ^/stories/?$ http://dev.explorersedge.ca/blog/

above your existing RedirectMatch , or below it, but modify, in that case, existing to 在您现有RedirectMatch之上或之下,但在这种情况下,将现有RedirectMatch修改为

RedirectMatch 301 ^/stories/(.+)$ /$1

so, that it will work only for /stories/ with at least one symbol after it (otherwise .* matches 0 or any number of symbols). 因此,它仅适用于/stories/及其后至少一个符号(否则.*匹配0或任意数量的符号)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM