Removing index.php in codeigniter -htaccess

假装没事ソ 提交于 2019-12-12 02:00:04

问题


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”


回答1:


This should work

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



回答2:


Just try this it's working means reply me

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



回答3:


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']).'/');


来源:https://stackoverflow.com/questions/27896459/removing-index-php-in-codeigniter-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!