【问题标题】:htaccess redirect subdirectory to roothtaccess 将子目录重定向到根目录
【发布时间】:2015-06-03 16:46:59
【问题描述】:

我可以添加什么规则来获得以下结果?

我想将包含某个目录的任何搜索重定向到主页。例如,当有人尝试...

test.com/example
...or...
test.com/example/something
...they end up at...
test.com

我尝试过的大多数东西都可以正常工作,但总是在重定向后将目标目录之后的内容附加到域中,例如...

test.com/example/something
...leads to...
test.com/something

这不是我想要的。谢谢

我尝试过的代码...

RewriteRule ^example/(.*)$ http://www.test.com [L,R=301]
and
Redirect 301 /example http://www.test.com

更新 这似乎可以解决它...

RedirectMatch 301 ^/example/ /
Redirect 301 /example http://www.test.com/

谢谢!

【问题讨论】:

  • 发布您正在使用的实际代码。

标签: apache .htaccess redirect


【解决方案1】:

试试:

RewriteEngine On
RewriteRule ^example/ / [L,R=301]

RedirectMatch 301 ^/example/ /

【讨论】:

  • 添加到原始问题的代码。感谢您为我指明正确的方向!
  • @ChadSeay 你不应该需要Redirect 行。这与RedirectMatch 相同,但没有正则表达式。
猜你喜欢
  • 2021-04-04
  • 1970-01-01
  • 1970-01-01
  • 2015-10-08
  • 2017-06-26
  • 2014-02-21
  • 2023-04-10
  • 2016-09-23
  • 1970-01-01
相关资源
最近更新 更多