如何向 CodeIgniter 应用程序添加一些静态路由?
如何配置 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样修改你的 .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
告诉 mod_rewrite 忽略 url(如果它是实际文件),而RewriteCond %{REQUEST_FILENAME} !-d
告诉 mod_rewrite如果它是目录,则忽略它。Modify your .htaccess like so:
RewriteCond %{REQUEST_FILENAME} !-f
tells mod_rewrite ignore the url if it's an actual file, andRewriteCond %{REQUEST_FILENAME} !-d
tells it to ignore it if it's a directory.