CodeIgniter Forums
Can't configure 'remove index.php' - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Can't configure 'remove index.php' (/showthread.php?tid=66384)



Can't configure 'remove index.php' - planteg - 10-18-2016

Hi,

I just can't succeed in removing index.php  Huh. I googled, found many references to this, unsuccessful. I also search the forum, loads of posts, again without success.

The codeigniter directory is under /var.
  • I activated mod_rewrite (apache2 2.4.10)
  • I edited config.php: $config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI';
  • I created/modifdied .htaccess file as per instructed in the documentation (CodeIgniter 3.1.0), in three places: /var/www/html, /var/codeigniter
I still need to include index.php in the URL. In order to check if one of the three .htaccess is hit, I added garbage as the first line, but got no error.

Within all pages I read, I just can't find the right procedure. What is it ?

Thanks


RE: Can't configure 'remove index.php' - Ayrese - 10-18-2016

Please paste your .htaccess file content here.


RE: Can't configure 'remove index.php' - planteg - 10-19-2016

Hi Ayrese,

here we go.

In /var/codeigniter/application (not edited)

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

In /var/codeginiter

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

In /var/www

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

In /var/www/html

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

Thanks for your help.


RE: Can't configure 'remove index.php' - Wouter60 - 10-19-2016

Put your .htaccess file in the same folder as index.php

My version:
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

# Prevent file browsing
Options -Indexes

In my config.php:
PHP Code:
$config['base_url']    = 'http://www.my-domain.com/' //example!
$config['index_page'] = '';
$config['uri_protocol']    = 'AUTO'



RE: Can't configure 'remove index.php' - planteg - 10-19-2016

Hi Wouter60,

tried your suggestion, but it still doesn't work. I added garbage at the beginning of the .htaccess file to get an error, but didn't get it, so that .htaccess file is not read I guess.

In a browser I get a 404 "The requested URL /wactrl was not found on this server." when I type http://cdesys.dlinkddns.com:180/wactrl

For sure wactrl is not in the /www/html directory. If I add index.php, all is well.


RE: Can't configure 'remove index.php' - dave friend - 10-19-2016

If the garbage you added at the beginning of .htaccess is not producing an error that would tend to indicate the either mod_rewrite is not active or that .htaccess is not in the correct place. .htaccess should be in the same directory as index.php

You can view loaded apache modules by using the linux command console and the command apache2ctl -M Look for rewrite_module in the list that appears.


RE: Can't configure 'remove index.php' - planteg - 10-19-2016

Hi Dave,

from https://docs.bolt.cm/3.0/howto/making-sure-htaccess-works I got the clue to check if Apache configuration enables .htaccess. In fact that was turned of. I changed this in apache2.conf:

Code:
<Directory "/var/www/htdocs">
   AllowOverride None

I changed None to All and got some results. The first .htaccess file accessed is in /var/www, and the second one is in /var/www/html. But then I get the AH00124 error: exceeded the limit of 10 internal redirects. Looks like it's lost somewhere in the forest. Having rewrites to log to level3, I learned that the server loops doing rewrite until the limit is reached.

On top of that, the rewrite is done wrong at the beginning:


Code:
strip per-dir prefix: /var/www/html/wactrl -> html/wactrl
applying patern '.' to uri 'html/wactrl'
rewrite 'html/wactrl' -> 'index.php'
add per-dir prefix index.php/ -> /var/www/index.php'
internal redirect with /var/www/index.php/ [INTERNAL REDIRECT]

Right after this, all of this is done again until the limit is reached.
As far as I understand, the URI from the received is /var/www/html/wactrl, where wactrl is the controller name. Once edited, that should become /var/www/html/index.php/wactrl right ? But it does not. What is wrong ?

And why is there a loop inside /var/www ?

EDIT ON October 20th

Finally made it work. The problem was the RewriteRule. I changed it to:
Code:
RewriteRule html html/index.php

Then /var/www/html/wactrl is changed to /var/www/html/index.php/wactrl

In short RewriteRule line is:[img]file:///Desktop/regex.jpg[/img]

RewriteRule SearchExpression ReplaceExpression

where SearchExpression is the part of the URI to be replaced by ReplaceExpression. This is the short story because both expression can use regular expression.

If you wish to test what you need, go https://regex101.com/ You can test drive your expressions live until you are satisfied. A screen shot is attached.

Thanks