apache - 如果不正确,Apache 重定向到另一个子目录
问题描述
我有这样的文件夹结构
public_html/
test/
right/
file.json
wrong/
file.json
因此,例如 example.com/test/right/file.json 是一个有效的 url。
我想要做的是,如果他们在 test 中遇到任何其他问题/他们将被重定向到 wrong/file.json
所以例如
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
但我刚刚进入重定向循环。
解决方案
您可能正在寻找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
推荐阅读
- python - Python selenium xpath获取文本为空
- javascript - 从 localhost 动态加载视频并获取 206 Partial Content
- node.js - populate() 不返回所有相关模型字段
- google-chrome - 删除复制两行Imacros时写入的[EXTRACT]
- java - 字母频率排序数组
- google-analytics - 谷歌分析 - gtag 用户 ID 问题
- sql-server - 将 XML 文件数据插入现有表
- python - 如何在python中用集合大小的百分比标记维恩图?
- python - python JSON模块读取JSON文件时出错
- python - 如何在 Pandas 数据框中读取 JSON 对象