如何向CodeIgniter应用程序添加一些静态路由? [英] How do I add some static routes to a CodeIgniter app?
问题描述
如何配置一个CodeIgniter应用程序,以便我可以有一个目录只服务一些静态(不是MVC)html?
我想处理一些现有的链接,形式为:
http:/ /mysite/contactform/contact.html?queryvars
/ contactform目录中的任何东西,包括子目录(这只是一些css,js,等等)不应该通过CodeIgniter管道。什么是最好的办法来处理呢? (我通常是Windows dev,所以说得慢)我认为它必须在重写配置中完成吗?
routes.php是非常基本的:
$ route ['default_controller'] =home
从.htaccess重写规则:
#您可能希望www.example.com转发到example.com - 较短的网址更性感。
#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]
修改您的.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
告诉它,如果它是一个目录,忽略它。
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屋!