基本目录的重写规则

Rewrite Rule For Base Directory

所以我正在尝试重写以下示例。环顾四周,但找不到符合这种情况的正确 post。

这是旧页面的布局列表:

www.url.com/directory
www.url.com/directory/page1.html
www.url.com/directory/page2.php

我正在尝试通过 htaccess 重写以下方式:

Redirect 301 /directory /newdirectory
Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2

但是,第一个重写规则干扰了该路径中的旧子页面。因此,例如,使用上面的重写规则,将:

www.url.com/directory/page1.html

将用户指向:

www.url.com/newdirectory/page1.html

何时应该将用户指向没有原始文件扩展名的 slug:

www.url.com/newdirectory/page1

我能够解决的唯一方法是完全忽略 www.url.com/newdirectory/page1.html 规则。但是有一堆指向该基本路径的链接,所以我想重定向它。

如有任何帮助,我们将不胜感激。在此先感谢您的时间和帮助。

url-重写重定向重写规则

您需要将基本目录规则放在子页面规则之后:

Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2
Redirect 301 /directory /newdirectory