且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在codeigniter -htaccess中删除index.php

更新时间:2023-02-21 21:40:54

按照以下步骤操作:


  1. 按如下方式更改配置文件:



    $ config ['index_page'] ='';


    $ b b

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


  2. 使用以下.htaccess:


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



注意:.htaccess因服务器而异。一些服务器(例如:Godaddy)需要使用以下.htaccess:

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

请参阅此处



在base_url中使用以下代码:

  $ config ['base_url'] ='http'。 ('isset($ _ SERVER ['HTTPS'])&& $ _SERVER ['HTTPS'] =='on')?''':'')。'://'.$_SERVER ['HTTP_HOST' ] .str_replace('//','/',dirname($ _ SERVER ['SCRIPT_NAME'])。'/'); 


Im trying to remove index.php from the url for the past 4 days but not successful.

http://domainName.com/CI/index.php/controller-name/function/parameter

CI is the folder hosted in godaddy.

/
.htaccess
CI

After googling, I tried with the following codes but getting only a blank page or error:500 and also I didn't understand the logic. Please someone help me to find where Im going wrong.

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

2nd

RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 

I also changed the line in, CI/application/config/config.php

$config['index_page'] = '';

$config['uri_protocol'] = "REQUEST_URI"

Follow the following step:

  1. Change the config file like this:

    $config['index_page'] = '';

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

  2. Use the following .htaccess:

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

Note: .htaccess vary depending on server. Some server (e.g.: Godaddy) need to use the following .htaccess:

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

see here

Use the following code in base_url:

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');