Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache .htaccess目录索引不工作_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache .htaccess目录索引不工作

Apache .htaccess目录索引不工作,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有一个在Linux/UNIX上运行的网站,但我对.htaccess文件及其语法一无所知 如果您转到http://pr.bananapages.net系统不会产生任何结果。 但是如果你加上文件名,它就会出现。例:http://pr.bananapages.net/index.html 注意:URL指向共享访问主机服务器上的子文件夹,但这并不重要,因为当您键入www.bananapages.net/pr/hamshack(这就是快捷DNS地址指向的地方)时,如果不实际指定它,它仍然不会生成inde

我有一个在Linux/UNIX上运行的网站,但我对.htaccess文件及其语法一无所知

如果您转到
http://pr.bananapages.net
系统不会产生任何结果。 但是如果你加上文件名,它就会出现。例:
http://pr.bananapages.net/index.html

注意:URL指向共享访问主机服务器上的子文件夹,但这并不重要,因为当您键入
www.bananapages.net/pr/hamshack
(这就是快捷DNS地址指向的地方)时,如果不实际指定它,它仍然不会生成index.html文件

我已经尝试了所有我能找到的关于
DirectoryIndex
的东西,但是如果不使用文件名…(index.html),我就无法让它工作

这是我当前的
.htccess
文件

Options -MultiViews

DirectoryIndex system.php index.php

<IfModule mod_rewrite.c>
DirectoryIndex system.php index.php index.html

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)\.(.*)$
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]

# Google sitemap controller
RewriteRule ^sitemap.xml$ tmp/sitemap.xml [L]
RewriteRule ^tmp/sitemap.xml$ tmp/sitemap.xml [L]
RewriteRule ^index.html$ index.html [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)(\.xml|\.php([0-9]*)|\.tpl|\.phtml|\.ini|\.inc|/)$ system.php?_p=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ system.php?_p=$1 [QSA,L]

</IfModule>

# compresses text, html, javascript, css and xml
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
</IfModule>
选项-多视图
DirectoryIndex system.php index.php
DirectoryIndex system.php index.php index.html
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_URI}!(.*)\.(.*)$
重写规则^(.+[^/])$http://%{http_HOST}%{REQUEST_URI}/[L,R=301]
#谷歌网站地图控制器
重写规则^sitemap.xml$tmp/sitemap.xml[L]
重写规则^tmp/sitemap.xml$tmp/sitemap.xml[L]
重写规则^index.html$index.html[L]
RewriteCond%{REQUEST_FILENAME}-f
重写规则^(.*)(\.xml\.php([0-9]*)\.tpl\.phtml\.ini\.inc./)$system.php?\u p=$1[QSA,L]
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$system.php?\u p=$1[QSA,L]
#压缩文本、html、javascript、css和xml
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE应用程序/xml应用程序/xhtml+xml应用程序/rss+xml
AddOutputFilterByType DEFLATE应用程序/javascript应用程序/x-javascript
注意:如果我重命名
.htaccess
文件,它将在不指定文件名(index.html)的情况下工作。我相当肯定在这个
.htaccess
文件中有什么东西阻止了它以所需的方式工作。

您可以尝试以下方法:

在你所有的

重写cond%{REQUEST_FILENAME}-f

因此,将其加倍,也就是说,仅当它既不是目录也不是文件时才进行重写:

编辑 (在Debian/Apache2中测试)

看看是否效果更好?请注意一些评论无限循环重写规则。

以下是答案

# Rules for subfolders
# for pr.bananapages.net
RewriteRule ^pr/(.*)$ pr/$1 [L]
# for jm.bananapages.net    
      RewriteRule ^jm/(.*)$ jm/$1 [L]
# and so on....
      RewriteRule ^dr/(.*)$ dr/$1 [L]
RewriteRule ^usvi/(.*)$ usvi/$1 [L]
RewriteRule ^bvi/(.*)$ bvi/$1 [L]
RewriteRule ^kitts/(.*)$ kitts/$1 [L]
RewriteRule ^ar/(.*)$ ar/$1 [L]
RewriteRule ^tt/(.*)$ tt/$1 [L]
我不知道为什么这样做有效,但似乎确实有效。。。
戴尔

我的副总裁也有类似的情况

我希望我的默认主页是login.php,因此如果有人要访问http://[ip]/[folder]/,它将只加载我在[folder]中的.htaccess中设置的login.php文件

所以我在.htaccess中设置了'DirectoryIndex login.php',但是

它不会起作用,相反,当我转到http://[ip]/[folder]/时,我会得到一个403,因为我没有任何index.html或index.php

所以

我决定检查apache配置文件httpd.conf,并在DirectoryIndex下将'login.php'作为已经存在的列表的一部分,然后重新启动httpd服务并


这对我有用

首先,删除除DirectoryIndex system.php index.html之外的所有代码,然后重试。如果有效,那么代码将在其他地方本地化。如果它不工作,那么system.php的代码无效,因此是500 ISE的原因。检查您的服务器错误日志以获取提示。@OhGod为什么我做系统管理员并且已经做了20多年&通常我不会将概述的绝大多数指令放在
.htaccess
文件中。但是你太咄咄逼人了,我会删除我的评论和帖子,除了这个,这样你就可以解决这个问题了。嘿。。。谢谢大家的意见。。。也许你能帮我弄清楚我有什么版本的操作系统,以及其他两个文件可能在哪里。。。我在一个共享的托管环境中,所以除了我的托管包中的htdocs根文件夹之外,我没有其他访问权限…@user2975488是否加载了mod_rewrite?正如你所知,我做了一件你的家人推荐的事情。。。我在DirectoryIndex system.php index.html之后删除了所有内容,并且它工作正常,因此该行下面的某些内容导致它失败。。。和:如何判断是否加载了mod_rewrite?好的,我试过你的想法,但它会导致主页失败。我得到:错误,在主页上找不到请求的URL(404),但是pr.bananapages.net的URL确实出现了。我需要让他们两个都上来。你读过我关于行的评论了吗:RewriteRule^(.*)$system.php?\u p=$1[QSA,L]?我隔离了引起错误的线路。请阅读我的评论。提前感谢…添加-d仅在此处:重写cond%{REQUEST_FILENAME}-已重写COND%{REQUEST_FILENAME}-f RewriteRule^(.*)$system.php?_p=$1[QSA,L]Jacouh:这正是我之前做的,我告诉过你结果。有问题的孩子在这一行:RewriteRule^(.*)$system.php?\u p=$1[QSA,L]-->感谢您的持续努力和支持。我想我们必须希望其他人也在读这篇文章。。Dale您可能不会测试它,您是否注意到这行错误:RewriteCond%{REQUEST_FILENAME}-恐怕我错过了你想告诉我的。。。你的意思是有一行语法错误吗?请把它指给我看,因为我看不到有没有。。。请告知。。。
# Rules for subfolders
# for pr.bananapages.net
RewriteRule ^pr/(.*)$ pr/$1 [L]
# for jm.bananapages.net    
      RewriteRule ^jm/(.*)$ jm/$1 [L]
# and so on....
      RewriteRule ^dr/(.*)$ dr/$1 [L]
RewriteRule ^usvi/(.*)$ usvi/$1 [L]
RewriteRule ^bvi/(.*)$ bvi/$1 [L]
RewriteRule ^kitts/(.*)$ kitts/$1 [L]
RewriteRule ^ar/(.*)$ ar/$1 [L]
RewriteRule ^tt/(.*)$ tt/$1 [L]