我正在尝试将 404 json fales 重定向到 404.json (以“{}”作为内容)。但 apache 正在将文件夹重定向到具有相同文件夹名称的 html 文件,并且任何自定义 404.json 重定向都会失败。
文件结构:
- /示例1/
- /示例2/
- /example1.html
- /example2/data.json
- /数据.json
工作(重定向到 404.html):
- http://example.com/example3/ http://example.com/example3/
工作(重定向到 404.json):
- http://example.com/not-exists.json http://example.com/not-exists.json
- http://example.com/example3/data.json http://example.com/example3/data.json
- http://example.com/example2/data.json http://example.com/example2/data.json
工作(打开文件):
- http://example.com/example1.html http://example.com/example1.html
- http://example.com/data.json http://example.com/data.json
-
http://example.com/example2/ http://example.com/example2/(列出文件夹中的文件)
不工作(默认 apache 404):
- http://example.com/example1/ http://example.com/example1/
- http://example.com/example1/not-exists.json http://example.com/example1/not-exists.json
- http://example.com/example2/not-exists.json http://example.com/example2/not-exists.json
apache 似乎正在将“example1/”重定向到“example1.html”,特别是当我尝试访问目录中的文件时,例如http://example.com/example2/data.json http://example.com/example2/data.json,显示404消息:
在此服务器上找不到请求的 URL /example2.html/data.json。
即使没有 .htaccess,也会发生这种情况!所有的问题都是因为example1.html文件。
访问:
# 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 文件映射配置,但我找不到任何相关信息。它仅发生在部署服务器上,对于本地主机来说没问题。 =/
像这样有MultiViews
关掉:
Options +FollowSymLinks -MultiViews
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
RewriteRule \.json$ 404.json [L,NC]
# 404 page
RewriteRule ^ 404.html [L]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)