Codeigniter- how load new page after removing index.php

送分小仙女□ 提交于 2019-12-06 13:43:55

You need URL Rewrite module for this to work. How to get this working depends on the web server you use.

For Apache, edit httpd.conf and uncomment (remove leading #) the following line then restart the webserver.

LoadModule rewrite_module modules/mod_rewrite.so

Add/edit .htaccess file in your CodeIgniter root folder and insert this.

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

If you get RewriteEngine not allowed here error, make sure the web root folder of CodeIgniter allows FileInfo override in your webserver config httpd.conf.

AllowOverride FileInfo

Bishweswar Mondal

Add below lines in your .htaccess file.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L]
pawansgi92

You can change your route file using below example. In string I am passing controller and function (method) name. And in $route array I am passing pretty name as I like.

#Route file path : CI_project/applications/config/routes.php

$route['default_controller'] = "Dashboard";
$route['contact-us'] = "dashboard/contact_us";

But please keep in mind that if you want to make above code work you have to enable rewrite module and give this code in .htaccess.

.htaccess file code:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /prjectName/
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
 # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: Pawan Nagar
<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!