htacess重定向索引文件时,尝试访问目录 [英] htacess redirect on index file when try to access dir
问题描述
试图拒绝访问所有文件,除了index.pl。首先,我拒绝所有,之后允许访问index.pl。下一步code正常工作。
Trying to deny access to all files except index.pl. First I deny all, after that allow access to index.pl. Next code works properly.
Order Allow,Deny
Deny from all
<Files "index.pl">
Order Deny,Allow
Allow from all
</Files>
但添加的.htaccess文件与此内容后,出现了以下问题: 当我尝试访问的 mysite.com / 的(不index.pl)服务器说,这是被禁止的。
But after adding .htaccess file with this content appeared the following issue: When I try to access mysite.com/ (without index.pl) server says it's forbidden.
我尝试添加的DirectoryIndex index.pl
,code已经变得如此:
I tried to add DirectoryIndex index.pl
, code has become so:
Order Allow,Deny
Deny from all
<Files "index.pl">
Order Deny,Allow
Allow from all
</Files>
DirectoryIndex index.pl
这并没有帮助我。
It didn't help me.
我要在文件中写入限制所有文件,除了index.pl和网站不能正常工作,而无需添加 /index.pl
链接?也许有另一种方法做我想要什么?
谢谢!
What I have to write in file to restrict all files except index.pl and site would work properly without adding /index.pl
to link? Maybe there are another method to do what I want?
Thank you!
P.S:对不起,我不是很流利的英语。
p.s.: sorry for my not very good english.
推荐答案
使用的mod_rewrite
更精细的控制规则。试试这个code在 DOCUMENT_ROOT /的.htaccess
文件:
Use mod_rewrite
rule for finer control. Try this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule ^(?!(index|search)\.pl).+$ - [F,NC]
这篇关于htacess重定向索引文件时,尝试访问目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!