重写codeigniter的规则
这是我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要像上面那样使用 mod_rewrite 删除 index.php 文件,但使用 CodeIgniter 的路由功能将
example.com/model
重新路由到example.com/welcome/bil/model
。在你的routes.php配置文件中,你可以像这样定义一个新的路由:
那么,输入
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
toexample.com/welcome/bil/model
.In your routes.php configuration file, you can then define a new route like this:
So then, typing
example.com/abc123
would be equivalent toexample.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!