【问题标题】:.htaccess doesn't work on custom folders in codeigniter.htaccess 不适用于 codeigniter 中的自定义文件夹
【发布时间】:2015-02-22 08:05:10
【问题描述】:

我的网站在 Codeigniter 中运行。我有自己的文件夹名称自定义,我在其中放置了一个简单的 .htaccess,其中有

Deny from all

但是当我点击 www.example.com/custom 时,它会在浏览器中显示所有文件。但是,如果我点击 www.example.com/system,它会显示“禁止访问目录。”

我的文件夹结构如下。

mysite
mysite/system
mysite/custom
mysite/application

....

我在根文件中有不同的 .htaccess 并且重定向工作正常。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]  

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/woff
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
  ExpiresActive On
  ExpiresDefault A0
  <FilesMatch "\.(ico|ICO|pdf|PDF|flv|FLV|jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF|js|JS|css|CSS|swf|SWF)(\.gz)?$">
  ExpiresDefault "access plus 10 years"
  Header append Cache-Control “publicâ€
  Header unset ETag
  FileETag None
  Header set Expires "Thu, 15 Apr 2025 20:00:00 GMT"
  </FilesMatch>
  <FilesMatch “\.(xml|txt|html)$â€>
  ExpiresDefault A7200
  Header append Cache-Control “proxy-revalidateâ€
  </FilesMatch>
  <FilesMatch “\.(js|css)$â€>
  ExpiresDefault A259200
  Header append Cache-Control “proxy-revalidateâ€
  </FilesMatch>
</IfModule>

我有

Deny from all

在其余的子文件夹中。系统和应用程序文件夹随 CI 一起提供。 htaccess 在这个文件夹中工作正常。但是在我自己创建的“custom”文件夹中,htaccess 文件不起作用。

可能是什么问题?为什么它允许 htaccess 在默认文件夹中工作以及为什么它不能在用户创建的文件夹中工作

注意:我的 nginx 服务器中的设置相同。我现在正在上传另一个网站。它不适用于 apache 文件夹。

【问题讨论】:

  • 这个 .htaccess 的位置是什么?您确定此 .htaccess 已启用吗?
  • 我在根目录和子文件夹中都有 .htaccess。 root 中的 .htaccess 工作正常。我有一个子文件夹系统,自定义。 .htaccess 在系统文件夹中工作,而不是在自定义文件夹中。
  • 所以Deny from all 在某个文件夹中而不是在根目录中? Deny from all 是否从根 .htaccess 工作?
  • 是的。 .htaccess 从根文件夹工作正常
  • 好的,如果你想让人们帮助你,你需要提供更多有问题的细节,因为我不能一直在 cmets 部分提出很多问题。您在浏览器中输入了什么 URL,这个 .htaccess 位于何处等

标签: php apache .htaccess codeigniter amazon-ec2


【解决方案1】:

在您的/custom/.htaccess 中尝试此代码:

RewriteEngine On

Deny from all

【讨论】:

  • 无效果Anubhava..还是一样。
  • 我已经测试了完全相同的设置并在访问 URL 时收到 403 禁止错误:http://localhost/custom/ 其中/custom/ 是一个真实目录。
【解决方案2】:

对于 WINDOWS 使用 (CTRL + F5) 或对于 MACOS 使用 (Command + R) 删除您的浏览器缓存,然后重试,确保您的 mysite/custom 文件夹中有 (dot) .htaccess 而不仅仅是 htaccess。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 2023-03-13
    • 2011-12-19
    相关资源
    最近更新 更多