How to remove from the index.php url in Codeigniter

0

I have an application on my local server, I followed all steps so that index.php was removed from the url in codeigniter, my local machine worked perfectly. So I put the application on the internet, in my hosting and also worked perfectly when I enter. The problem started when I put SSL, now if I type my URL, my application loads normally and with the SSL certificate identified and validated, however the index.php appears in the URL, if I delete the URL the index.php and press ENTER, the site loads normally. The question is if I type the URL and enter, the index.php appears in the URL or if I enter through the link found in the google search. SSL I only have in my hosting, I do not have it on my local machine.

Following is the configuration of my .htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.php|content|robots\.txt)
RewriteCond $1 !^(index\.php|documentacao|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Note: I'm using a subdomain within my hosting.

I hope you can help me, thank you very much in advance.

    
asked by anonymous 20.09.2018 / 05:34

2 answers

0

Personal thanks to the solution proposed by Igor Cacerez that I was able to solve the problem. Just reinforcing, what led to the problem was the fact that I added two lines to my .htaccess that make the browser use https, because as I said earlier, I have SSL installed. I am referring to this passage:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

What I did to solve the problem was simply to add at the beginning of the file the piece of code proposed by Igor. Below is the before and after of my .htaccess file.

Before:

RewriteEngine on
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Then:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
20.09.2018 / 17:42
0

Put this code in your .htaccess file

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

Now go to the config.php file and change the following lines:

Put the url of your system.

$config['base_url'] = 'http://SUA URL';

I left this line exactly like this:

$config['index_page'] = '';

And now, just create your routes, and you no longer need to use index.php

    
20.09.2018 / 14:11