如何向 CodeIgniter 应用程序添加一些静态路由?

发布于 2024-09-19 23:36:01 字数 861 浏览 1 评论 0原文

如何配置 CodeIgniter 应用程序,以便我可以拥有一个仅提供一些静态(非 MVC)html 的目录?

我想处理一些现有的链接,其形式为:

http://mysite/contactform/contact.html /contactform 目录中的任何内容

(包括子目录(只是一些 css、js、图像等))不应经过 CodeIgniter 管道。处理这个问题的最佳方法是什么? (我通常是 Windows 开发人员,所以慢慢说)

我认为它必须在重写配置中完成?

routes.php 非常基本:

$route['default_controller'] = "home";

从 .htaccess 重写规则:

# you probably want www.example.com to forward to example.com -- shorter URLs are sexier.
#   no-www.org/faq.php?q=class_b
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteEngine on
RewriteCond $1 !^(index\.php|contact\.php|images|css|js|video|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

How do I configure a CodeIgniter app so I can have one directory that will just serve some static (not MVC) html?

I want to handle some existing links, in the form of:

http://mysite/contactform/contact.html?queryvars

Anything in the /contactform directory including sub-directories (which is just some css, js, images,etc) should not go through the CodeIgniter pipeline. What is the best way to handle that? (I am normally a Windows dev, so speak slowly)

I figure it has to be done in the rewrite config?

routes.php is very basic:

$route['default_controller'] = "home";

rewrite rules from .htaccess:

# you probably want www.example.com to forward to example.com -- shorter URLs are sexier.
#   no-www.org/faq.php?q=class_b
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteEngine on
RewriteCond $1 !^(index\.php|contact\.php|images|css|js|video|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

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

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

发布评论

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

评论(1

記柔刀 2024-09-26 23:36:01

像这样修改你的 .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f 告诉 mod_rewrite 忽略 url(如果它是实际文件),而 RewriteCond %{REQUEST_FILENAME} !-d 告诉 mod_rewrite如果它是目录,则忽略它。

Modify your .htaccess like so:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f tells mod_rewrite ignore the url if it's an actual file, and RewriteCond %{REQUEST_FILENAME} !-d tells it to ignore it if it's a directory.

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