How to remove from the index.php url in Codeigniter

Asked

Viewed 592 times

1

I have an application on my local server, I followed all the steps to have index.php removed from the url in codeigniter, on my local machine worked perfectly. Therefore, 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, but the index.php appears in the URL, if I delete from the URL the index.php and ENTER hit, the site loads normally. The question is whether I enter the URL and enter, the index.php appears in the URL or enter through the link found in the google search. SSL only have on my hosting, I do not have on my local machine.

Follow my file . htaccess configuration

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 am using in a subdomain within my hosting.

I hope you can help me, thank you so much.

2 answers

1


Thanks to the solution proposed by Igor Cacerez, I was able to solve the problem. Just to reiterate, what led to the occurrence of the problem was the fact that I added it to mine. htaccess two lines that cause the browser to use https, because as I said earlier, I have SSL installed. I refer to that stretch:

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

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

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]

Afterward:

<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]

1

Put this code in your file . htaccess

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

Now access the config.php file and change the following lines:

Enter the url of your system.

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

I left that line exactly like this:

$config['index_page'] = '';

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.