我在网站上注意到很多404,看起来像:
/category1/category2/slug-name/subdirectory
category1
, category2
和 slug-name
都不同,但是子目录永远不应该存在(但是它总是相同的子目录。)
我只想创建一个简单的重定向,我只是不太熟悉.htaccess语法。
基本上重定向应为:
https://www.example.com/no/matter/what/is/here/subdirectory
to
https://www.example.com/no/matter/what/is/here/
我尚未测试过,但我认为它应该有效:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)/subdirectory$ $1/ [QSA,R=301,L]
</IfModule>
您也可以使用RedirectMatch Directive
在root文件夹中的htaccess文件中尝试一下
RedirectMatch 301 ^/(.*)/subdirectory/?$ /$1