简体   繁体   English

htaccess 重定向不适用于已删除的子目录

[英]htaccess redirect not working for deleted subdirectory

I have a WordPress site that had a /blog directory that held another WP site.我有一个 WordPress 站点,该站点的 /blog 目录包含另一个 WP 站点。 After moving that WP install to its own site and deleting that directory, I haven't been able to set up redirects for that missing folder.将该 WP 安装移动到其自己的站点并删除该目录后,我无法为该丢失的文件夹设置重定向。

What I would like is to redirect example.com/blog/article-1 to example.com/article-1我想要的是将 example.com/blog/article-1 重定向到 example.com/article-1

I used the following to redirect, but get a 404 error我使用以下重定向,但出现 404 错误

RewriteEngine On
RedirectMatch 301 ^blog(/.*)?$ https://www.example.com/$1

I have tested this with ... ^blog1(/.*)?$... and it worked as expected, but anything related to /blog it seems to ignore the.htaccess file.我已经用... ^blog1(/.*)?$...测试了它,它按预期工作,但与 /blog 相关的任何内容似乎都忽略了 .htaccess 文件。

There is no longer a directory there, so there shouldn't be any other.htaccess file that is taking precedence.那里不再有目录,所以不应该有任何 other.htaccess 文件优先。

Any ideas as to why this isn't redirecting right?关于为什么这不正确重定向的任何想法?

If you can't beat them, join them.如果你不能打败他们,就加入他们。 I ended up resolving this by creating the /blog directory that it was trying to look in and put in a new .htaccess file to redirect back to the root directory.我最终通过创建它试图查看的 /blog 目录并放入一个新的 .htaccess 文件以重定向回根目录来解决这个问题。

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

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