重写codeigniter的规则

发布于 2024-09-02 19:06:17 字数 714 浏览 0 评论 0原文

这是我在 CI 中的控制器,

class Welcome extends Controller {

 function Welcome()
 {
  parent::Controller(); 
  }

 function index()
 {

 }
 function bil($model='')
 { }

我想做一个重写,以便它

http://example.com/index.php/welcome/bil/model

成为

http://example.com/model

我的 htaccess 我认为

RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]
#RewriteRule ^(.*)$ /index.php/welcome/bil/$1 [L]

它应该像删除 /index.php/welcome/ 部分一样简单 但是当我取消注释最后一行时,它会出现500内部服务器错误

this is my controller in CI

class Welcome extends Controller {

 function Welcome()
 {
  parent::Controller(); 
  }

 function index()
 {

 }
 function bil($model='')
 { }

I want to do a rewrite so that

http://example.com/index.php/welcome/bil/model

becomes

http://example.com/model

in my htaccess I have

RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]
#RewriteRule ^(.*)$ /index.php/welcome/bil/$1 [L]

I thought it should be as easy as removing the /index.php/welcome/ part
but when I uncomment the last line it get 500 internal server error

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

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

发布评论

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

评论(1

嘴硬脾气大 2024-09-09 19:06:17

您需要像上面那样使用 mod_rewrite 删除 index.php 文件,但使用 CodeIgniter 的路由功能example.com/model 重新路由到 example.com/welcome/bil/model

在你的routes.php配置文件中,你可以像这样定义一个新的路由:

// a URL with anything after example.com 
// will get remapped to the "welcome" class and the "bil" function, 
// passing the match as a variable
$route['(:any)'] = "welcome/bil/$1";

那么,输入example.com/abc123将相当于example.com/welcome/bil/abc123

请注意,URL 中仅允许使用 $config['permissed_uri_chars'](位于 config.php 文件中)允许的字符。

希望有帮助!

You'll want to use mod_rewrite to remove your index.php file like you have above, but use CodeIgniter's routing features to reroute example.com/model to example.com/welcome/bil/model.

In your routes.php configuration file, you can then define a new route like this:

// a URL with anything after example.com 
// will get remapped to the "welcome" class and the "bil" function, 
// passing the match as a variable
$route['(:any)'] = "welcome/bil/$1";

So then, typing example.com/abc123 would be equivalent to example.com/welcome/bil/abc123.

Note that only characters permitted by $config['permitted_uri_chars'] (which is located in your config.php file) are allowed in a URL.

Hope that helps!

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