Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that ci url will not work with index.php

Is it possible that ci url will not work with index.php.I dont want to add index.php in url. If someone adds index.php in url it should not work.I have tried many methods . Please give me suggestion. I have tried but it's not working

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

for e.g

if i use below url This should work..............

`example.com/abc`

if i use below url shouldn't work

`example.com/index.php/abc`
like image 764
user3198563 Avatar asked Aug 03 '18 03:08

user3198563


3 Answers

Create .htaccess file in your root directory And keep this code into it

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

Open application/config/config.php

    //find the below code   
$config['index_page'] = "index.php" 
//replace with the below code
$config['index_page'] = ""

/find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI" 
like image 70
suresh Avatar answered Nov 06 '22 05:11

suresh


You can use:

RewriteEngine On

# 403 Forbidden for index.php
RewriteCond %{THE_REQUEST} index\.php [NC]
RewriteRule ^ - [F]

# Rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
like image 36
Croises Avatar answered Nov 06 '22 05:11

Croises


In Config.php

$config['base_url'] = 'http://localhost/website/';
$config['index_page'] = '';

# If Live site
# $config['base_url'] = 'http://stackoverflow.com/';

In .htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Check my answer on another question Set up the base URL in codeigniter

like image 3
Abdulla Nilam Avatar answered Nov 06 '22 05:11

Abdulla Nilam