Apache 正在将文件夹重定向到具有相同名称的文件 .html [英] Apache is redirecting folder to file .html with the same name

查看:59
本文介绍了Apache 正在将文件夹重定向到具有相同名称的文件 .html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 404 json fales 重定向到 404.json(以{}"作为内容).但是 apache 正在将文件夹重定向到具有相同文件夹名称的 html 文件,并且任何自定义 404.json 重定向都会失败.

I'm trying to redirect 404 json fales to 404.json (with "{}" as content). But apache is redirecting folder to a html file with the same folder name and any custom 404.json redirect fails.

文件结构:

  • /example1/
  • /example2/
  • /example1.html
  • /example2/data.json
  • /data.json

工作(重定向到 404.html):

工作(重定向到 404.json):

工作(打开文件):

  • http://example.com/example1.html
  • http://example.com/data.json
  • http://example.com/example2/ (list files in folder)

不工作(默认 apache 404):

似乎 apache 正在将example1/"重定向到example1.html",尤其是当我尝试访问目录中的文件时,例如 http://example.com/example2/data.json,显示 404 消息:

It seems apache is redirecting "example1/" to "example1.html", especially when I try to access a file inside the directory like http://example.com/example2/data.json, shows 404 message:

在此服务器上找不到请求的 URL/example2.html/data.json.

即使没有 .htaccess 也会发生!所有问题都是因为example1.html文件.

It happens even without the .htaccess! All the problem because the example1.html file.

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 来说没问题.=/

Maybe it is some apache file mapping configuration but I can't find anything about it. It happens only for deploy server, for localhost it's fine. =/

推荐答案

MultiViews 关闭的情况下像这样:

Have it like this with MultiViews turned off:

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]

这篇关于Apache 正在将文件夹重定向到具有相同名称的文件 .html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆