【问题标题】:How to remove subdirectory in wordpress using htaccess如何使用 htaccess 删除 wordpress 中的子目录
【发布时间】:2022-01-02 06:59:12
【问题描述】:

我需要更改网址:

http://example.com/*/a/any.html
http://example.com/*/b/any.html
http://example.com/*/c/any.html

到:

http://example.com/a/any.html
http://example.com/b/any.html
http://example.com/c/any.html

如果直接访问:

http://example.com/a/any.html
http://example.com/b/any.html
http://example.com/c/any.html

保持这种状态

提前感谢大家的帮助

【问题讨论】:

  • “我需要重写”——大概你的意思是“重定向”?
  • 你能帮帮我吗?

标签: wordpress .htaccess mod-rewrite


【解决方案1】:

如果 /subdir 是您需要删除的子目录,那么您可以在根 .htaccess 文件的顶部,在现有 WordPress 指令之前尝试类似以下内容:

RewriteRule ^subdir(/(a|b|c)/[\w-]+\.html)$ $1 [R=302,L]

如果 子目录 实际上是任何子目录,请尝试以下操作:

RewriteRule ^[^/]+(/(a|b|c)/[\w-]+\.html)$ $1 [R=302,L]

【讨论】:

  • 谢谢,但如果子目录有不同的名称,这不起作用
  • @miguelangellopezcarrizales 我已经更新了我的答案以包含 any 子目录的解决方案。
  • 感谢您的奉献,我制作了这个适用于 RewriteRule ^([^/]+)/(a|b|c)/(.*)$ $2/$3 [R =301,L]
  • @miguelangellopezcarrizales 好的,但是没有必要捕获第一个路径段(目录),因为它被丢弃了。它还取决于 RewriteBase 的设置。而且它还不仅仅匹配.html 文件,如问题中所述 - 它匹配任何 URL 路径,包括多个路径段?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 2019-10-03
  • 2011-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多