I can not delete the index.php in the URL in CodeIgniter

0

Greetings

I follow this course . Here they teach how to remove (or rather hide) the index.php in CodeIgniter URLs by configuring a .htaccess file in the root of the application, which did not work for me and I would like to know why.

Here is my repository:

link

And here my .htaccess:

link

    
asked by Felipe Pino 30.08.2016 в 20:54
source

3 answers

2

First you must modify the file "CodeIgniter / application / config / config.php" (As I see you already did, but I indicate it in case someone else serves this answer) taking into account that it should now look like this:

$config['index_page'] = ""

In addition to the previous step, in a project I did with CodeIgniter 2.0 I used the following code in a .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
AddDefaultCharset UTF-8

I recently tested it on CodeIgniter 3.0 and it's still working. The version of php that I use is 5.6.19 and I have the redirect module (mod_rewrite) active on my Apache server

    
answered by 22.09.2016 в 21:23
0

I'm sure this code will help you:

    #Activamos la reescritura SI SOLO SI el mod_rewrite se encuentra activado, así se evitan errores 500
<IfModule mod_rewrite.c>

    # Suponiendo que el listado de directorios esté desactivado, permitimos indexación y activamos el rewrite
    Options +FollowSymLinks -Indexes
    RewriteEngine on

    # Usualmente "AllowOverride" debería estar en 'All' en el apache.conf/vhost.conf, pero si no descomentas lo siguiente para evitar un error 404
    #AllowOverride All

    # Se supone que la regla aplica desde el directorio donde se encuentra el .htaccess pero si es necesario lo especificas, siendo / la raiz de dominio
    #RewriteBase /

    # con esta instrucción bloqueamos el acceso a la carpeta system, si es que se encuentra en el directorio web
    RedirectMatch 403 ^/(system).*$

    # Antes de redireccionar, se verifica que la petición no sea a un directorio o archivo existente
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Si el archivo/directorio no existe, redireccionamos
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

If your PHP version is 5.2.6 or higher:

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

If your PHP version is 5.2.5 or lower:

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

Even with this it may not work for you, so try this code:

RewriteEngine on RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://**tuWeb**.es/ [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://**tuWeb**.es/ [R=301,L]

    
answered by 30.08.2016 в 22:38
0

Hello, I have had the same problem but after giving so much, I found the solution; my directory has the first capital letter that is: www / Kyrstalos / and in the line in .htaccess I had it like this:

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

And I gave myself error again and again, what I did was to put everything in lowercase and wualaaaa, then it was like this:

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

Solved all the problems ...

Here is my .htaccess in case it helps:

# Suponiendo que el listado de directorios esté desactivado, permitimos indexación y activamos el rewrite
Options +FollowSymLinks -Indexes
RewriteEngine on

# Usualmente "AllowOverride" debería estar en 'All' en el apache.conf/vhost.conf, pero si no descomentas lo siguiente para evitar un error 404
#AllowOverride All

# Se supone que la regla aplica desde el directorio donde se encuentra el .htaccess pero si es necesario lo especificas, siendo / la raiz de dominio
#RewriteBase /

# con esta instrucción bloqueamos el acceso a la carpeta system, si es que se encuentra en el directorio web
RedirectMatch 403 ^/(system).*$

# Antes de redireccionar, se verifica que la petición no sea a un directorio o archivo existente
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Si el archivo/directorio no existe, redireccionamos
RewriteRule ^(.*)$ /krystalos/index.php/$1 [L]

ErrorDocument 404 /krystalos/index.php
    
answered by 07.12.2016 в 16:13