[英]Not removing index.php in codeigniter
I am sending form data (views to controller) but i want to remove index.php from url. 我正在发送表单数据(对控制器的视图),但我想从URL中删除index.php。 For this I removed index.php from config.php but it is not working for me.
为此,我从config.php中删除了index.php,但它对我不起作用。 How can I remove index.php from the url and post data without using index.php?
如何不使用index.php从网址中删除index.php并发布数据? Here is my code in views:
这是我的视图代码:
<form method="post" action="<?php echo base_url()?>/index.php/Home/login">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" name="name"id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input maxlength="10" minlength="3" type="password" name="name" class="form-control" id="exampleInputPassword1" placeholder="Password"required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
You need to change your helper calls from action="<?php echo base_url()?>/index.php/Home/login"
to action="<?php echo site_url('home/login')?>"
when you need a link to the controller. 您需要在操作时将助手调用从
action="<?php echo base_url()?>/index.php/Home/login"
更改为action="<?php echo site_url('home/login')?>"
需要到控制器的链接。 For static resources (css, uploads, etc), keep calling base_url()
. 对于静态资源(css,上传等),请继续调用
base_url()
。
You'll also need to have mod_rewrite
properly configured as suggested in the comments. 您还需要按照注释中的建议正确配置
mod_rewrite
。
1)make .htaccess file and put this code 1)制作.htaccess文件并放入此代码
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
2)change 2)改变
$config['index_page'] = '';
remove index.php present in config.php file
create file .htaccess in your root system folder and add code below 在根系统文件夹中创建文件.htaccess并在下面添加代码
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
then you can remove index.php in your code 然后您可以在代码中删除index.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.