【问题标题】:htaccess rewriterule ignore index.htmlhtaccess rewriterule 忽略 index.html
【发布时间】:2012-01-16 17:43:40
【问题描述】:

我正在使用 CodeIgniter 和 .htaccess 重写 URL,但我希望它忽略 index.html

这样我们就可以随时上传index.html,因为这将是一个临时登陆页面。通过index.php 上的主站点链接。

这是当前在.htaccess 中的内容,我已将服务器的目录索引设置为index.html index.php

RewriteEngine on

RewriteCond $1 !^(index\.html|index\.php|js|img|fonts|data|css|uploaded|mobile_devices|audioplayer|emails|robots\.txt|archive_blog)

RewriteRule ^(.*)$ /index.php/$1 [L]

感谢您的帮助

【问题讨论】:

    标签: .htaccess codeigniter mod-rewrite codeigniter-2


    【解决方案1】:

    您似乎想重写目录中不存在的所有内容。

    试试这个而不是你当前的 RewriteCond:

    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1
    

    【讨论】:

      【解决方案2】:

      您可以通过使用 FilesMatch 指令直接限制对它的访问,而不是使用 RewriteCond 来忽略 index.html 文件。 FilesMatch 接受一个正则表达式,它可以根据文件名(例如 index.html)或任何正则表达式进行过滤。

      阻止对 index.html 文件的访问

      <FilesMatch "index\.html$">
          Order allow,deny
      </FilesMatch>
      

      这将完全拒绝对 index.html 文件的访问。我承认,我不知道这会对搜索引擎抓取产生负面影响。

      要了解有关 FilesMatch 指令的更多信息,请参阅 http://httpd.apache.org/docs/current/mod/core.html#filesmatch


      对于您当前拥有的该列表中的其余目录,您可以锁定所有目录访问权限,而不管名称如何。它将为您提供更多的报道。

      Options -Indexes
      

      要了解有关选项指令的更多信息,请参阅http://httpd.apache.org/docs/current/mod/core.html#options


      最后,您的新 .htaccess 文件将如下所示:

      # Protect specific files from access
      <FilesMatch "index\.html$">
          Order allow,deny
      </FilesMatch>
      
      # Hide directory listing for URL's mapping to a directory
      Options -Indexes
      
      # Follow all symbolic links in this directory 
      Options +FollowSymLinks
      
      # General rewrite rules
      <IfModule mod_rewrite.c>
        RewriteEngine on
      
        RewriteBase /
      
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L,QSA]
      </IfModule>
      

      【讨论】:

        【解决方案3】:

        为什么不使用内置的environment 函数?

        您可以创建一个“维护”环境并将基本控制器设置为您想要的任何内容。然后你只需要编辑 index.php 文件来指定你想要的环境。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-07-20
          • 1970-01-01
          • 2014-10-06
          • 2011-06-20
          • 2018-04-04
          • 2020-05-30
          • 2013-11-15
          • 2015-12-29
          相关资源
          最近更新 更多