CodeIgniter: removing 'index.php' from URL

2019-09-02 03:14发布

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.

7条回答
Anthone
2楼-- · 2019-09-02 03:40

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

查看更多
混吃等死
3楼-- · 2019-09-02 03:47

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.

查看更多
迷人小祖宗
4楼-- · 2019-09-02 03:49

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

查看更多
可以哭但决不认输i
5楼-- · 2019-09-02 03:55

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

查看更多
看我几分像从前
6楼-- · 2019-09-02 03:57

enter image description here

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

查看更多
淡お忘
7楼-- · 2019-09-02 03:57

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

查看更多
登录 后发表回答