代码之家  ›  专栏  ›  技术社区  ›  Matt Coady

如果不在正确的子目录中,Apache将重定向到另一个子目录

  •  0
  • Matt Coady  · 技术社区  · 6 年前

    public_html/
      test/
        right/
          file.json
        wrong/
          file.json
    

    例如示例.com/test/right/file.json是有效的url。

    例如

    example.com/test/right/file.json -> .../right/file.json
    example.com/test/blah/file.json -> .../wrong/file.json
    example.com/test/whatever/file.json -> .../wrong/file.json
    

    我试过这样的方法:

    RedirectMatch 301 ^/((?!right).*)$ http://example.com/test/wrong/file.json
    

    1 回复  |  直到 6 年前
        1
  •  0
  •   Anonymous user3428448    6 年前

    你可能在找 ErrorDocument :

    ErrorDocument 404 http://example.com/test/wrong/file.json
    

    只允许 right/file.json

    RedirectMatch 301 ^/(?!(right|wrong)/file\.json$) http://example.com/test/wrong/file.json