使用 .htaccess 将子目录重定向到根 URL

Redirect subdirectory to root URLs using .htaccess

对我在此处找到的其他一些 questions/answers 稍作调整,但对我不起作用。

我的网站有一个 www.mywebsite.eu/subdirectory where all the website's pages were located. I have now moved all the files to www.mywesbite.eu 的子目录。 /子目录基本上已被删除。

我如何进行 .htaccess 重定向,使任何 /subdirectory URL 重定向到没有子目录的 URL。

举个例子: www.mywebsite.eu/subdirectory/webpage.html 现在需要 www.mywebsite.eu/webpage.html

我希望有一种更简单的方法,而不是在我网站上的所有页面上进行重定向,只需说“如果有人请求其中包含 /subdirectory 的 URL,请将他们带到相同 URL,只是开头没有 /subdirectory

我最初尝试过

RewriteRule ^subdirectory/(.*)$ www.mywebsite.eu/ [L,R=301]

但这没有用。我一开始就有这个:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此规则:

RewriteEngine On

RewriteRule ^subdirectory/(.*)$ / [L,NC,R=302,NE]