繁体   English   中英

.htaccess不允许子目录工作

[英].htaccess not allowing sub-directory to work

这是.htaccess文件

RewriteEngine on
RewriteCond $1 !^(index\.html|index.php|administrator|system|template|js|lib|favicon\.ico|robots\.txt)
RewriteRule ^(.*)$ /index.html?tpl=$1 [L]


Options +FollowSymlinks

但是,发生的事情是以下所有文件夹都不允许我进入其中并查看PHP文件。

|administrator|system|template|js|lib

我认为通过将文件放在RewriteCond ,它可以使用户仍然转到http://example.com/news/happy ,然后再转到index.php?tpl = etc等,但是它阻止了我前进到任何子目录中

http://example.com/system/index.php

我不知道这是否适合您。 但是,我要做的是添加此规则,以将调用加载到任何.php文件中,而不会以.php结尾。 不论是否结束,您都可以通话。

例如,您可以调用my_url.com/myfolder/myfile ,它将使用友好的URL加载myfile.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

我想建议您先阅读有关mod重写的信息

1-将那条线放在顶部

 Options +FollowSymlinks

该行要求您的服务器遵循符号链接,但我建议您使用更安全的选项“ SymLinksIfOwnerMatch”

资源:

http://httpd.apache.org/docs/2.2/mod/core.html#options#FollowSymLinks

RewriteEngine on

启用或禁用运行时重写引擎

来源: http : //httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteengine

 RewriteCond $1 !^(index\.html|index.php|administrator|system|template|js|lib|favicon\.ico|robots\.txt)

干得好 。 该规则要求Web服务器添加重写条件以忽略正则表达式中列出的所有内容

我也添加了正则表达式为您解释

 ! 

不等于^开头

 RewriteRule ^(.*)$ /index.html?tpl=$1 [L]

您要求将其他所有内容都写到index.html?tpl = $ 1 **我认为您的意思是index.php我将假设您不需要查询字符串

我想建议使用更好的方法来处理排除

 RewriteEngine On
 Options +FollowSymLinks
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_URI} !(index\.html|index.php|administrator|system|template|js|lib|favicon\.ico|robots\.txt)
 RewriteRule ^(.*)$ /index.html?tpl=$1 [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM