【问题标题】:Codeigniter .htaccess: Give public access to all files but not the folderCodeigniter .htaccess:授予对所有文件但不是文件夹的公共访问权限
【发布时间】:2013-09-18 23:03:07
【问题描述】:

我的文件格式如

  application
       - controllers
       - views etc...
  assetes
       - Images
       - Css etc...

我的 .htaccess 文件如下:

#Deny from all
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

我的问题是资产文件夹访问每个任何用户查看所有图像和所有 css 文件但需要的只是用户访问资产文件夹文件而不是访问整个文件夹

请帮帮我 谢谢!

【问题讨论】:

    标签: php .htaccess codeigniter


    【解决方案1】:

    只需将index.html 文件放入要阻止目录访问的文件夹中即可完成阻止目录访问。

    这是标准 CodeIgniter 安装的方式。下面的index.html 文件可以在application\controllers 文件夹中找到。

    <html>
    <head>
        <title>403 Forbidden</title>
    </head>
    <body>
        <p>Directory access is forbidden.</p>
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      在您的 htaccess 中使用以下行 RewriteCond %{REQUEST_FILENAME} !-f 这是用于文件访问

      RewriteCond %{REQUEST_FILENAME} !-d 这是用于字典访问

      【讨论】:

      • Order allow,deny
        Allow from all
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        请使用以下代码更新您的 .htaccess RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 2014-10-14
      • 1970-01-01
      • 2016-03-14
      • 2019-06-18
      相关资源
      最近更新 更多