2010-06-28 39 views
0

我相信这可能很简单,但我的知识在这方面确实不太好,而且我似乎也没有把它做好。Mod重写* .html文件(CodeIgniter)

我有以下文件结构:

/cms (renamed from system) 
cms.php (renamed from index.php, added to DirectoryIndex in .htaccess) 
.htaccess 
index.html 
page1.html 
/css 
/js 

我也有从CI维基的.htaccess。我认为需要调整的部分是:

#Checks to see if the user is attempting to access a valid file, 
#such as an image or css document, if this isn't true it sends the 
#request to cms.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ cms.php?/$1 [L] 

我希望大多数已存在的文件都可以访问,例如,和.js,.css,.png,.swf等,但任何.htm或.html将由cms.php处理。

例如,如果用户请求http://localhost/index.html,则将index.html传递给cms.php,或者如果请求http://localhost/dir/page.html,则传递dir/page.html。

+0

出于好奇,什么不正确与你有什么? – 2010-06-28 19:15:01

+0

它的工作原理,但我试图捕捉HTML文件来处理它们之前输出。例如,用户请求index.html,“index.html”被传递给codeigniter应用程序,该应用程序加载文件,进行任何更改,然后回显内容。需要它以这种方式工作以保持简单 - 设计者只需要将3个文件(/ cms,cms.php和.htaccess)转储到cms中即可。 – Josh 2010-06-28 19:23:59

+1

啊,我现在明白了。 (我知道这个问题的原始答案有问题,但不想在我确定你想要什么之前发布答案,看起来你已经知道了,但很高兴听到它的工作!) – 2010-06-28 19:49:33

回答

0

找到的教程,并提出了以下几点:

RewriteRule ^(.*\.html)$ cms.php?/$1 [NC] 

所以任何请求的结尾是.html传递给cms.php,导致像cms.php一个URL/index.html的,这cms.php可以处理和输出。

0
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond $1 !^(*\.js|*\.png|*\.css|*\.swf|folder1|folder2) 
RewriteRule ^(.*)$ index.php/$1 
RewriteRule ^.\.htm cms\.php 
RewriteRule ^.\.html cms\.php 
</IfModule> 

您可以添加你不想重新定向到RewriteCond行其它扩展和/或文件夹。

+0

啊! , 好。有没有办法将其反转,所以我指定了哪些文件应该被重写(.htm,.html)? – Josh 2010-06-28 17:21:27

+0

是的。你可以在文件中增加额外的'RewriteRule'行。我编辑了2个附加重写规则的例子,将'.htm'和'.html'文件重定向到'cms.php'。 – stormdrain 2010-06-28 17:47:04

+0

嗯,无法让它正常工作。不过,我想我已经对它进行了排序 - 找到了一个教程,并且提出了似乎可以完成这项工作的RewriteRule ^(。* \。html)$ cms.php?/ $ 1 [NC]。不管怎么说,还是要谢谢你! – Josh 2010-06-28 19:21:54