Apache htaccess删除文件夹重定向

Apache htaccess删除文件夹重定向,apache,.htaccess,url,redirect,Apache,.htaccess,Url,Redirect,从url中删除文件夹时出现问题。我希望google/旧链接不会被破坏。旧网页有几个类似这样结构的部分 example.com/news/items/entry1.html example.com/news/items/entry2.html example.com/blog/items/foo.html 新页面的URL如下所示: example.com/news/entry1 example.com/news/entry2 example.com/blog/foo 删除html相当简单 &l

从url中删除文件夹时出现问题。我希望google/旧链接不会被破坏。旧网页有几个类似这样结构的部分

example.com/news/items/entry1.html
example.com/news/items/entry2.html
example.com/blog/items/foo.html
新页面的URL如下所示:

example.com/news/entry1
example.com/news/entry2
example.com/blog/foo
删除html相当简单

<IfModule mod_rewrite.c>
RewriteEngine On

# Send would-be 404 requests to Craft

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php [QSA,L]

RewriteCond %{THE_REQUEST} /([^.]+)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
</IfModule>

重新启动发动机
#向Craft发送可能的404请求
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}^/(favicon\.ico | apple touch图标。*\.png)$[NC]
重写规则(+)index.php[QSA,L]
重写cond%{u请求}/([^.]+)\.html[\s?][NC]
重写规则^/%1[R=302,L,NE]
我正在努力解决的部分是删除“项目”部分。我发现的规则只适用于请求路径,如“example.com/items/subfolder1/…”


非常感谢您的帮助。

要从URL中删除
/items/
,您可以在
.htaccess
文件中使用以下内容:

RewriteEngine On
RewriteRule ^(.*)/items /$1 [L,R=301]
例如,这将使用URL:并将其转换为


在测试此操作之前,请确保清除缓存。

要从URL中删除
/items/
,可以在
.htaccess
文件中使用以下命令:

RewriteEngine On
RewriteRule ^(.*)/items /$1 [L,R=301]
例如,这将使用URL:并将其转换为

在测试此项之前,请确保清除缓存