2011-12-09 99 views
0

我使用CodeIgniter和.htaccess来重写网址,但我希望它忽略index.htmlhtaccess rewriterule ignore 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] 

感谢所有帮助

回答

4

像你想重写并不真正存在的一切,而看起来在你的目录中。

试试这个而非目前的RewriteCond的:

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

你为什么不使用内置的environment功能?

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

2

而不是使用RewriteCond忽略index.html文件,而是可以直接通过使用FilesMatch指令来限制对它的访问。 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>