问题描述
我现在要解决两个多小时.我有一个使用.htaccess来管理URL的个人站点.看起来像这样:
I'm trying to solve this for more than two hours now.I have a personal site which uses .htaccess to manage urls.It looks like this:
RewriteEngine on
RewriteBase /
...
RewriteRule ^sklad/?$ index.php?action=sklad
RewriteRule ^sklad/user/([0-9]+)?$ index.php?action=sklad&user=$1
RewriteRule ^sklad/folder/(.+)?$ index.php?action=sklad&folder=$1
RewriteRule ^sklad/file/(.+)?$ engine/ajax/sklad.php?file=$1
RewriteRule ^sklad/logout/?$ index.php?action=sklad&op=logout
...
RewriteRule ^admin/?$ admin.php
RewriteRule ^admin/news/?$ admin.php?action=news
前五个可以正常工作. admin/可以正常工作.但是,当我尝试访问 admin/news/时,我得到了一个空白页. Apache没有显示或记录任何错误,也没有输出. admin.php?action = news 工作正常.
the first five ones work fine. The admin/ one works fine. But when I try to access admin/news/, I get a blank page. No errors displayed or logged by Apache, and no output. admin.php?action=news is working fine.
服务器上物理上存在 sklad/和 admin/文件夹. 但是,当我将admin/文件夹重命名为其他名称 OR 时,将最后一个RewriteRule更改为
Both sklad/ and admin/ folders physically exist on the server. BUT when I rename the admin/ folder to something else OR change the the last RewriteRule to something like
RewriteRule ^admin123/news/?$ admin.php?action=news
我可以访问 admin123/news/.如果与服务器上存在的实际文件夹有关,那么为什么前五个规则有效?这没有道理.
I can access admin123/news/. If it has something to do with the actual folder existing on the server, then why the first five rules are working? This doesn't make sense.
我没主意了,希望这里有人帮忙...
I'm out of ideas, hope someone here helps...
推荐答案
这不是错误,听起来像是内容协商(通过mod_negotiation)已打开,并且正在做您不想要的事情.可以通过类型映射或 MultiViews 选项打开协商. Typemap的设置有点明确,所以我假设由于您不知道为什么会发生这种情况,因此您没有设置映射到news.php
的特定类型.因此,您可能已打开多视图.您可以通过从Options
语句中将其删除来关闭它:
It's not a bug, it sounds like content negotiation (via mod_negotiation) is turned on and it's doing something you don't want. Negotiation can be turned on via a type map or the MultiViews option. Typemaps are a little explicit to setup, so I'm assuming since you don't know why this is happening, you haven't set of a specific type that maps to news.php
. So you've probably got Multiviews turned on. You can turn it off by either removing it from an Options
statement:
# remove this word -----------v
Options Indexes FollowSymLinks Multiviews
它可以在htaccess,服务器配置,vhost配置,某些配置包含文件等任何位置.因此,您也可以在htaccess文件中显式取消设置(只要您未在htaccess文件中显式设置它).相同的文件):
This could be anywhere, in your htaccess, server config, vhost config, some config include file, etc. So you can also explicitly unset it in your htaccess file (as long as you aren't also explicitly setting it in the same file):
Options -Multiviews
这篇关于.htaccess RewriteRule返回空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!