怎样一些静态路由添加到codeIgniter应用程序? [英] How do I add some static routes to a CodeIgniter app?

查看:107
本文介绍了怎样一些静态路由添加到codeIgniter应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置codeIgniter的应用程序,所以我可以有一个目录,这将只是服务于某种静态的(不MVC)的HTML?

我要处理一些现有链接,形式为:

HTTP://mysite/contactform/contact.html queryvars

东西在/联系形式目录包括子目录(这只是一些CSS,JS,图像等)不应该通过codeIgniter管道去。什么是处理的最佳方式? (我是一个正常的Windows开发,这样慢慢说吧)

我想它在重写配置做?

routes.php文件是很基本的:

  $路线['default_controller'] =家;

从的.htaccess重写规则:

 #你可能想www.example.com转发给example.com  - 较短的网址是性感。
#no-www.org/faq.php?q=class_b
RewriteEngine叙述在
的RewriteCond%{HTTP_HOST} ^ WWW \\。(。+)$ [NC]
重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]RewriteEngine叙述上
的RewriteCond $ 1 ^(指数\\ .PHP |联系\\ .PHP |图片| CSS | JS |视频|机器人\\ .txt)的!
重写规则^(。*)$的index.php / $ 1 [L]


解决方案

修改你的.htaccess像这样:

  RewriteEngine叙述在
的RewriteCond%{HTTP_HOST} ^ WWW \\。(。+)$ [NC]
重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php / $ 1 [L]

的RewriteCond%{} REQUEST_FILENAME!-f 讲述了mod_rewrite忽略网址,如果它是一个实际的文件,而的RewriteCond%{} REQUEST_FILENAME!-d 告诉它忽略它,如果它是一个目录。

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]

解决方案

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.

这篇关于怎样一些静态路由添加到codeIgniter应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆