CodeIgniter: removing 'index.php' from URL

2019-09-02 03:58发布

问题:

I have answered this question previously and even posted the answer to it by myself. I tried most of the answered questions, but it still didn't work. The first question is regarding placement of the .htaccess file, should I keep it with application folder or inside it? and the next question is 'How should I remove the index.php from URL'?

.htaccess code:

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Config.php code:

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

and if possible do also suggest a detailed tutorial regarding how to customize TankAuth or any other authentication library which can be easier. I am using Windows 8.1 and Wamp Server.

Any suggestion or help is appreciated.

回答1:

Use this in your .htaccess file:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA] 

place ./ before your index.php rewrite rule.

or this

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


For more detail refer link:https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html



回答2:

it works on me, I use v2.2.6 by the way

  • Create .htacccess on the same dir as your index.php
  • Modify index_page and base_url value in /application/config/config.php

here is what it looks like

picture image link



回答3:

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

application > config > config.php

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

definitely it will work.



回答4:

Try this htaccess works fine windows 7 and 8.1 and xampp

Make sure you place the .htaccess in main directory and not the application folder.

Options +FollowSymLinks
Options -Indexes

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Config

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

More htaccess https://github.com/riwakawebsitedesigns/htaccess_for_codeigniter



回答5:

i think it will help you,

.htaccess

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

in config.php

    $http = 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://';
    $newurl = str_replace('index.php', '', $_SERVER['SCRIPT_NAME']);
    $config['base_url'] = "$http".$_SERVER['SERVER_NAME'].''.$newurl;
    $config['modules_locations'] = array('http://localhost/astrido_admin/application/' . 'modules/');

$config['index_page'] = '';

Thanks



回答6:

in config.php change this

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

and in .htaccess(NOTE: this should be place outside application folder)

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

Note: There are lot of duplicate question. So before Ask New Question please check your dropdown menu(its comes with when you start typing title of your question) whether its exist or answer provided.



回答7:

1.config.php

$config['index_page'] = 'index.php';     change  to     $config['index_page'] = '’;

2.Create .htaccess file

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