0

I have problem with rewrite in CodeIgniter. I'm starting to study CI but the url is bothering me.

http: //localhost/projetoci/index.php/restrict

I already enabled rewrite mode in apache.

LoadModule rewrite_module modules / mod_rewrite.so

I created the .htaccess file

RewriteEngine on
RewriteCond $ 1! ^ (Index \ .php | resources | robots \ .txt)
RewriteCond% {REQUEST_FILENAME}! -F
RewriteCond% {REQUEST_FILENAME}! -D
RewriteRule ^ (. *) $ Index.php / $ 1 [L, QSA]

but none of this makes removing index.php from url. I've looked at other topics and couldn't solve it.

Hans One
  • 3,329
  • 27
  • 28
  • Possible duplicate of [CodeIgniter removing index.php from url](https://stackoverflow.com/questions/19183311/codeigniter-removing-index-php-from-url) – Sherif Salah Jul 29 '19 at 13:51

1 Answers1

0

In application/config folder, find and replace the below code in config.php file.

$config['index_page'] = "";

Now set .htaccess file as below.

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /projetoci/

    #This bit rewrites your host name to include www    
    #RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]  
    #RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /projetoci/index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /projetoci/index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /projetoci/index.php?/$1 [L]

</IfModule>
G_real
  • 1,137
  • 1
  • 18
  • 28
  • $config['index_page'] = ''; and i use your code for htacess but if i try " localhost/projetoci/restrict " go to " http://localhost/dashboard/ " xampp page – william santos Jul 29 '19 at 13:56
  • Please check your **routes.php** file in config folder. May be you have url routing over there. Also please check in **config.php** file `$config['uri_protocol'] = 'REQUEST_URI';` – G_real Jul 29 '19 at 14:02
  • $route['default_controller'] = 'home'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; $route['restrict'] = 'restrict'; $config['uri_protocol'] = 'REQUEST_URI'; i only have "home" and " restrict " separated in 2 " controller " public function index(){ $this->template->show("login.php"); } – william santos Jul 29 '19 at 14:08
  • Please check "restrict" controller and index function in it. Is there any "redirect" code to dashboard view? – G_real Jul 29 '19 at 14:13
  • So in 'login.php' file, it may redirects to dashboard. Because there may be a condition like if you are already logged in, you will be redirected to dashboard page. – G_real Jul 29 '19 at 14:17
  • in "login.php" there is only one container. with the word "Login". I didn't continue because I wanted to solve the URL problem – william santos Jul 29 '19 at 14:18
  • Please check `login.php` controller. From there it may be redirecting to Dashboard as I said in my previous comment. – G_real Jul 29 '19 at 14:23
  • Does it redirects to `localhost/projetoci/dashboard` or `localhost/dashboard`? – G_real Jul 29 '19 at 14:27
  • localhost/dashboard this is a xampp page. no make sense – william santos Jul 29 '19 at 14:31
  • Does it gives any error after redirecting to 'localhost/dashboard' page? Here it redirects you to completely outside of your local CI project. It happens beacuse it can't find any requested view file in `restrict`. – G_real Jul 29 '19 at 14:40
  • I don't make a mistake. just sends me out of the local project. – william santos Jul 29 '19 at 14:42
  • I have made changes code above. I have added your local CI project name i.e. /projetoci in front of RewriteRule. Previously it wasn't there so it was redirecting out of project. Please update it with edited code and check. – G_real Jul 29 '19 at 15:38
  • https://imgur.com/a/zlpKfPU the problem persists. but thank you very much. Soon I try again. – william santos Jul 29 '19 at 18:56