简体   繁体   English

.htaccess不允许子目录工作

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

Here is the .htaccess file 这是.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

However what is happening is that all the following folders wont allow me to go into them and view a PHP file. 但是,发生的事情是以下所有文件夹都不允许我进入其中并查看PHP文件。

|administrator|system|template|js|lib

I thought by putting the files in RewriteCond that it would allow a user to still go to http://example.com/news/happy which then would go to the index.php?tpl=etc etc but it has stopped me from going into any subdirectory like 我认为通过将文件放在RewriteCond ,它可以使用户仍然转到http://example.com/news/happy ,然后再转到index.php?tpl = etc等,但是它阻止了我前进到任何子目录中

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

I don't know if this would work for you. 我不知道这是否适合您。 But what I do is to add this rules to load calls to any .php file without the .php ending. 但是,我要做的是添加此规则,以将调用加载到任何.php文件中,而不会以.php结尾。 You can call both, with or without that ending. 不论是否结束,您都可以通话。

For example, you can call my_url.com/myfolder/myfile and it will load myfile.php , with the friendly URL. 例如,您可以调用my_url.com/myfolder/myfile ,它将使用友好的URL加载myfile.php

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

i would like to recommend that you read about mod rewrite first 我想建议您先阅读有关mod重写的信息

1 - put that line at top 1-将那条线放在顶部

 Options +FollowSymlinks

That line ask your server to follow symlinks but i would like recommend that you use the more secure option "SymLinksIfOwnerMatch" 该行要求您的服务器遵循符号链接,但我建议您使用更安全的选项“ SymLinksIfOwnerMatch”

Source: 资源:

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

RewriteEngine on

Enables or disables runtime rewriting engin 启用或禁用运行时重写引擎

Source: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteengine 来源: 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)

Here you go . 干得好 。 that rule ask the web server to add rewrite Condition to ignore everything listed in your regex 该规则要求Web服务器添加重写条件以忽略正则表达式中列出的所有内容

also i have added regex explain for you 我也添加了正则表达式为您解释

 ! 

not equal ^ Start with 不等于^开头

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

you are asking to write everything else to index.html?tpl=$1 ** I think you mean index.php i will assume that you don't need the query string 您要求将其他所有内容都写到index.html?tpl = $ 1 **我认为您的意思是index.php我将假设您不需要查询字符串

i would like to recommend using a better way to handle the excluding 我想建议使用更好的方法来处理排除

 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