0

I am sending form data (views to controller) but i want to remove index.php from url. For this I removed index.php from config.php but it is not working for me. How can I remove index.php from the url and post data without using 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>
gview
  • 14,876
  • 3
  • 46
  • 51
  • using htaccess you can remove it. – Sachin Sep 27 '18 at 05:39
  • 4
    Possible duplicate of [CodeIgniter removing index.php from url](https://stackoverflow.com/questions/19183311/codeigniter-removing-index-php-from-url) – xitas Sep 27 '18 at 05:40

4 Answers4

0

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. For static resources (css, uploads, etc), keep calling base_url().

You'll also need to have mod_rewrite properly configured as suggested in the comments.

msg
  • 7,863
  • 3
  • 14
  • 33
  • i tried but then form data not posting/hit on controller – Disha kamboj Sep 27 '18 at 06:06
  • 1
    @Dishakamboj so you are not reaching the controller at all? Looks like a `mod_rewrite` problem. For `Rewrite` to work in `.htaccess` you need at least `AllowOverride FileInfo` in your server config – msg Sep 27 '18 at 06:13
0

1)make .htaccess file and put this code

 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

 $config['index_page'] = ''; 

 remove index.php present in config.php file
0

Just click here make the htaccess file in the root folder.

Now remove index.php from this line.

<form method="post"  action="<?php echo base_url()?>/index.php/Home/login"> 
Bergin
  • 188
  • 3
  • 12
0

create file .htaccess in your root system folder and add code below

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

then you can remove index.php in your code

asnka go
  • 57
  • 1
  • 5