大网数据广告活动
服务器运维问答

How to redirect pages in subdirectories if a parent page is redirected

· 52CE 我爱测

I'm using wordpress on nginx and I have redirected one page using this: rewrite ^/main-page/ http://www.example.com/new-main-page/ permanent; Problem is that the page has several child pages and and all child links are broken. He…

问题原文

原帖链接 · bpy · CC BY-SA 3.0

I'm using wordpress on nginx and I have redirected one page using this:

rewrite ^/main-page/ http://www.example.com/new-main-page/ permanent;

Problem is that the page has several child pages and and all child links are broken.

Here is an example of the problem:

http://www.example.com/main-page/exists-but-is-broken/

The above URL doesn't works because the main page now is the **new-main-page**

How can I redirect all child pages to the new URL ^/new-main-page/something-here/ using (perhaps a wildcard)?

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 3.0

To capture the end of the source URI and append it to the end of the target URI, try:

rewrite ^/main-page(/.*)?$ http://www.example.com/new-main-page$1 permanent;

If the server is http://www.example.com (i.e. this is the same server), you can omit that part:

rewrite ^/main-page(/.*)?$ /new-main-page$1 permanent;

See this document for details. And this resource on regular expressions.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-01-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。