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

发布于 2024-09-07 04:19:20 字数 903 浏览 1 评论 0原文

我确信这可能非常简单,但我在这方面的知识确实不好,而且我似乎无法正确理解。

我有以下文件结构:

/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处理。

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

I'm sure this is probably really simple, but my knowledge really isn't good in this area, and I don't seem to be able to get it right.

I have the following file structure:

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

I also have the .htaccess from the CI wiki. The part I think needs adjusting is:

#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]

I want most files that already exist to be accessible, e.g. and .js, .css, .png, .swf etc, but any .htm or .html to be processed by cms.php.

For example, if the user requests http://localhost/index.html, index.html gets passed to cms.php, or if http://localhost/dir/page.html is requested, dir/page.html is passed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原来分手还会想你 2024-09-14 04:19:20
<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 行的其他扩展程序和/或文件夹。

<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>

you can add other extensions and/or folders that you do not want re-directed to the RewriteCond line.

蓝眸 2024-09-14 04:19:20

找到了一个教程,并提出了以下内容:

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

因此,任何以 .html 结尾的请求都会传递给 cms.php,从而产生像 cms.php/index.html 这样的 URL,cms.php 可以处理和输出该 URL。

Found a tutorial, and came up with the following:

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

So anything requested ending in .html is passed to cms.php, resulting in a URL like cms.php/index.html, which cms.php can process and output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文