-3

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".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shuvro Shuvro
  • 119
  • 1
  • 3
  • 10
  • I am not understanding your problem. You think your `.htaccess` file should remain empty despite what the documentation exactly tells you to put in there. Solution: snap out of it, RTM and follow the instructions. – Sparky Jan 04 '13 at 21:47
  • possible duplicate of [Remove index.php in codeigniter 2.1.0](http://stackoverflow.com/questions/9667226/remove-index-php-in-codeigniter-2-1-0) – Sparky Jan 04 '13 at 21:50

3 Answers3

1

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
Community
  • 1
  • 1
itsme
  • 48,972
  • 96
  • 224
  • 345
0

You need to replace "Deny from all" with this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

http://ellislab.com/codeigniter/user-guide/general/urls.html

swatkins
  • 13,530
  • 4
  • 46
  • 78
0

Looking at the official documentation, CodeIgniter URLs:

You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

RewriteEngine on<br>
RewriteCond $1 !^(index\.php|images|robots\.txt)<br>
RewriteRule ^(.*)$ /index.php/$1 [L]<br>

Also if you are using Apache place .htaccess file in your root web directory. For more information, look in Codeigniter .htaccess.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Karan Ashar
  • 1,392
  • 1
  • 10
  • 23