7

How to delete index.php from a CodeIgniter URL?

 2 years ago
source link: https://www.codesd.com/item/how-to-delete-index-php-from-a-codeigniter-url.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to delete index.php from a CodeIgniter URL?

advertisements

I am new to CodeIgniter. I have an XAMPP server on Windows 8. Everything is fine, but the problem is about my URL, it doesn't look friendly. It looks like localhost/ci/index.php/site/home (where ci is my root folder for CodeIgniter). I want to make the URL more clean, like localhost/ci/home, how can I do it?

My CodeIgniter version is 2.1.2.

I have done some research already, but in most of the cases it says to change the .htaccess file of CodeIgniter. But I have nothing in the .htaccess file; it's empty, except the line "Deny from all".


You can do this, in config/config.php:

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; //you can also leave blank this CI tend to find this by himself
$config['index_page'] = '';

And try the following .htaccess. I use it for many sites, and it satisfies me.

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

If it is not working yet, use a phpinfo(); and check if mod_rewrite is enabled. If it is not enabled, you can follow the instructions in Stack Overflow question How do you enable mod_rewrite? to enable that.

If it is not working yet and mod_rewrite is enabled yet, you can try to switch these in config/config.php:

$config['uri_protocol'] = 'AUTO'; //If not working, try one of these:
     'PATH_INFO'        Uses the PATH_INFO
    | 'QUERY_STRING'    Uses the QUERY_STRING
    | 'REQUEST_URI'     Uses the REQUEST_URI
    | 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK