Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess Mod Rewrite重写*.html文件(CodeIgniter)_.htaccess_Mod Rewrite_Codeigniter - Fatal编程技术网

.htaccess Mod Rewrite重写*.html文件(CodeIgniter)

.htaccess Mod Rewrite重写*.html文件(CodeIgniter),.htaccess,mod-rewrite,codeigniter,.htaccess,Mod Rewrite,Codeigniter,我相信这可能真的很简单,但我在这方面的知识真的不太好,而且我似乎无法正确理解 我有以下文件结构: /cms (renamed from system) cms.php (renamed from index.php, added to DirectoryIndex in .htaccess) .htaccess index.html page1.html /css /js 我还可以从CI wiki访问.htaccess。我认为需要调整的部分是: #Checks to see if the us

我相信这可能真的很简单,但我在这方面的知识真的不太好,而且我似乎无法正确理解

我有以下文件结构:

/cms (renamed from system)
cms.php (renamed from index.php, added to DirectoryIndex in .htaccess)
.htaccess
index.html
page1.html
/css
/js
我还可以从CI wiki访问.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处理

例如,如果用户请求,index.html被传递到cms.php,或者如果被请求,dir/page.html被传递


<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>
重新启动发动机 1美元^(*\.js.*\.png.*\.css.*\.swf | folder1 | folder2) 重写规则^(.*)$index.php/$1 重写规则^.\.htm cms\.php 重写规则^.\.html cms\.php

您可以添加其他扩展名和/或文件夹,这些扩展名和/或文件夹不希望重新定向到
RewriteCond
行。

找到了一个教程,并得出以下结论:

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

因此,任何以.html结尾的请求都会传递到cms.php,从而生成一个类似cms.php/index.html的URL,cms.php可以处理和输出该URL

啊,好的。有没有办法扭转它,所以我指定哪些文件应该被重写(.htm、.html)?是的。您可以向文件中添加其他
RewriteRule
行。我用两个附加重写规则的示例编辑了答案,这些规则将
.htm
.html
文件重定向到
cms.php
.Hmm,无法使其正常工作。然而,我认为我已经对它进行了分类——找到了一个关于它的教程,并提出了RewriteRule^(.*\.html)$cms.php?/$1[NC],似乎可以完成这项工作。无论如何谢谢你!出于好奇,您所拥有的东西有什么不正常的地方?很好,它工作了,但我试图捕获html文件,以便在输出之前对其进行处理。例如,用户请求index.html,“index.html”被传递到codeigniter应用程序,该应用程序加载文件,进行任何更改,然后回显内容。需要它以这种方式工作以保持简单-设计师只需在代码中转储3个文件(/cms、cms.php和.htaccess)即可将其cms化。啊,我现在明白了。(我知道这个问题的原始答案有问题,但在我确定你想要什么之前,我不想发布答案,看起来你已经找到了答案,很高兴听到它起作用了!)