显示.htaccess的权限被拒绝/目录索引 [英] Htaccess permission denied / Directory index shown

查看:156
本文介绍了显示.htaccess的权限被拒绝/目录索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问了[提问]: htaccess的反向目录在这里对反向路由。不过,我不断收到目录视图,而不是有问题的文件。

I asked a [question]: htaccess reverse directory here about reverse routing. However I keep getting the directory view instead of the file in question.

例如:我去/img/header.jpg我得到的文件夹的内容/ IMG /而文件header.jpg存在。我加-Indexes的选择,但只是导致成403禁止访问的消息。

For example: I go to /img/header.jpg I get the content of the folder /img/ while the file header.jpg exists. I added -Indexes in the options but that just results into a 403 forbidden access message.

如何修改我的htaccess显示IMGS / JS / CSS等,但仍然保持了递归结构?

How should I edit my htaccess to show imgs/js/css etc but still keep the recursive structure?

目前htacces:

 Options +FollowSymLinks -MultiViews -Indexes
 # Turn mod_rewrite on
 RewriteEngine On
 RewriteBase /

 RewriteCond %{DOCUMENT_ROOT}/$1/$2.php !-f
 RewriteRule ^(.*?)/([^/]+)/?$ $1/ [L]

 RewriteCond %{DOCUMENT_ROOT}/$1.php -f
 RewriteRule ^(.*?)/?$ $1.php [L]

在此先感谢

修改

我已经试过后直接添加以下行的RewriteBase /:

I have tried adding the following line directly after RewriteBase /:

RewriteCond %{REQUEST_FILENAME} !-f

这对大多数的文件。只有当它是图像/ CSS / JS / ICO /等本应只工作。我认为目前如果找到一个php文件,直接将努力。

This work for most files. Only this should only work when it are images/css/js/ico/etc. I think at the moment if it finds a php file directly it would work to.

我似乎无法弄清楚是如何获得其余的参数。

What I cant seem to figure out is how to get the remaining parameters.

 /index/foo/bar/for/

文件应该被发现是foo,我怎么在$ _GET 2其余参数?

File that should be found is foo , how do I get the 2 remaining parameters in a $_GET?

推荐答案

更​​改code到:

选项+了FollowSymLinks -MultiViews -Indexes

Options +FollowSymLinks -MultiViews -Indexes

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
# don't do anything
RewriteRule ^ - [L]

# if current ${REQUEST_URI}.php is not a file then
# forward to the parent directory of crrent REQUEST_URI
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php !-f
RewriteRule ^(.*?)/([^/]+)/?$ $1/ [L]

# if current ${REQUEST_URI}.php is a valid file then 
# load it be removing optional trailing slash
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

编辑:基于OP的评论这个解决方案填补了一个查询参数参数与路径的其余部分:

Based on OP's comments this solution fills a query parameter param with the remainder of a path:

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
# don't do anything
RewriteRule ^ - [L]

# if current ${REQUEST_URI}.php is not a file then
# forward to the parent directory of crrent REQUEST_URI
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php !-f
RewriteCond %{QUERY_STRING} ^(?:param=)?(.*)$
RewriteRule ^(.*?)/([^/]+)/?$ $1/?param=$2/%1 [L]

# if current ${REQUEST_URI}.php is a valid file then 
# load it be removing optional trailing slash
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

这篇关于显示.htaccess的权限被拒绝/目录索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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