How do I remove the \"index.php\"
sticking out in every path in codeigniter somewhere in the center?
I want clean non index.php-fied URLs
?
i tested this on apache2 on many different hosting and it works great.
use this htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
be sure you have enabled mod_rewirte
with a phpinfo();
then do this in config/config.php:
$config['index_url'] = '';
|
| 'AUTO' Default - auto detects
| '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
|
*/
$config['uri_protocol'] = 'AUTO';
if it doesn't works yet, try to change the $config['uri_protocol']='AUTO'
to one of the listed inside application/config/config.php
file on line 40/54:
sometimes i used : REQUEST_URI
instead of AUTO
or "QUERY_STRING"
for goDaddy hostings
All above methods failed for me and then I found that I was not changing AllowOverride None to AllowOverride All in my virtual host file at /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All <---- replace None with All
</Directory>
<Directory /var/www >
Options Indexes FollowSymLinks MultiViews
AllowOverride All <--- replace None with All
Order allow,deny
allow from all
</Directory>
...
This will help you paste this code in application folder in .htacess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
<IfModule mod_php5.c>
php_value short_open_tag 1
</IfModule>
place a .htaccess file in your root web directory
Whatsoever tweaking you do - if the above is not met - it will not work. Usually its in the System folder, it should be in the root. Cheers!
Copy past following code in your .htaccess
RewriteEngine on
Options -Indexes
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
As an .htaccess file, a good option is to use the one provided by the Kohana Framework:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
It's a well thought out .htaccess that just works.