Welcome Guest, Not a member yet? Register   Sign In
Why RewriteRule index.php [L] is no more sufficient
#1

[eluser]WebMada[/eluser]
Title: Why RewriteRule ^(.*)$ index.php?/$1 [L] is no more sufficient

Hello,

I am wondering why this piece of code that i've used in CI 1.7 doesn't work anymore in CI 2:
RewriteEngine on
RewriteRule ^(.*)$ /index.php?/$1 [L]

So now, how to do if we want to remove index.php in the URL?

I search in google and I found a trick like that:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Why in CI 2, we need now to use RewriteCond??
#2

[eluser]InsiteFX[/eluser]
Code:
# PHP5
<IfModule mod_php5.c>
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

#PHP4
<IfModule !mod_php5.c>
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
But the ? is required on some hosting providers!

InsiteFX
#3

[eluser]WebMada[/eluser]
indeed, ? is required by my hoster

Thanks, it's a good solution. Now I can restore in my config.php
$config['uri_protocol'] = 'AUTO' instead of $config['uri_protocol'] = 'REQUEST_URI'

My .htaccess looks like now:
Code:
RewriteEngine On
RewriteBase /test_uploads_ci2/

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# PHP5
<IfModule mod_php5.c>
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

#PHP4
<IfModule !mod_php5.c>
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>




Theme © iAndrew 2016 - Forum software by © MyBB