【发布时间】:2017-01-02 04:22:03
【问题描述】:
我正在尝试将 404 json fales 重定向到 404.json(以“{}”作为内容)。但是 apache 正在将文件夹重定向到具有相同文件夹名称的 html 文件,并且任何自定义 404.json 重定向都会失败。
文件结构:
- /example1/
- /example2/
- /example1.html
- /example2/data.json
- /data.json
工作(重定向到 404.html):
工作(重定向到 404.json):
- http://example.com/not-exists.json
- http://example.com/example3/data.json
- http://example.com/example2/data.json
工作(打开文件):
- http://example.com/example1.html
- http://example.com/data.json
- http://example.com/example2/(列出文件夹中的文件)
不工作(默认 apache 404):
- http://example.com/example1/
- http://example.com/example1/not-exists.json
- http://example.com/example2/not-exists.json
似乎 apache 正在将“example1/”重定向到“example1.html”,尤其是当我尝试访问目录内的文件时,例如 http://example.com/example2/data.json,显示 404 消息:
在此服务器上找不到请求的 URL /example2.html/data.json。
即使没有 .htaccess,它也会发生!都是因为example1.html文件的问题。
htaccess:
# Rewrite MOD
Options +FollowSymLinks
RewriteEngine On
# If requested resource exists as a file or directory go to it
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*) - [L]
# 404 json
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)\.json$ 404.json [L]
# 404 page
RewriteRule . 404.html [L]
也许这是一些 apache 文件映射配置,但我找不到任何关于它的信息。它只发生在部署服务器上,对于 localhost 很好。 =/
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite