Удалить index.php из URL-адресов CodeIgniter

Я пытаюсь получить доступ к URL-адресам CodeIgniter без «index.php». Вот шаги, которые я сделал:

  1. Проверено, что mod_rewrite включен – я установил правило для перенаправления всех запросов на google, которые работали. Также проверено, что установлено значение «AllowOverride All»

  2. Добавлен файл .htaccess со следующим:

    RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] 
  3. Задайте мою структуру каталогов на веб-сервере следующим образом:

     /home/wwwsunde/ -> application -> system -> public_html -> index.php -> .htaccess 
  4. Обновил файлы приложений / конфигов, чтобы пути к системе и приложениям были «../system» и «../application»,

  5. Попробуйте получить доступ к сайту с 2 URL-адресов.

     http://109.234.194.207/~wwwsunde/index.php/welcome/membership WORKS http://109.234.194.207/~wwwsunde/welcome/membership DOES NOT WORK 
  6. Я также установил переменную индексной страницы CodeIgniter в пустую строку в соответствии с руководством

Отобразится сообщение об ошибке:

 The requested URL /home/wwwsunde/public_html/index.php/welcome/membership was not found on this server. 

Я не в курсе, что может быть неправильным – это проблема с Apache или сервером, но я не уверен, что …

О … Я знаю, почему … сделайте это своим правилом перезаписи:

 RewriteRule .* index.php/$0 [PT] 

[L] у вас было просто «последнее правило», но не пришлось бы переписывать quit, чтобы вы спокойно справлялись с фоновой оболочкой игры. Это был бы бесконечный цикл. Если это не работает, укажите полный URL-адрес в переписывании, например:

  RewriteRule .* http://109.234.194.207/~wwwsunde/index.php/$0 [PT] 

Откуда вы поняли, что индексная страница должна быть пустой? Вы имеете в виду index.php? Это должно быть примерно так:

 <?php /* |--------------------------------------------------------------- | PHP ERROR REPORTING LEVEL |--------------------------------------------------------------- | | By default CI runs with error reporting set to ALL. For security | reasons you are encouraged to change this when your site goes live. | For more info visit: http://www.php.net/error_reporting | */ error_reporting(0); // ini_set("display_errors", "on"); /* |--------------------------------------------------------------- | SYSTEM FOLDER NAME |--------------------------------------------------------------- | | This variable must contain the name of your "system" folder. | Include the path if the folder is not in the same directory | as this file. | | NO TRAILING SLASH! | */ $system_folder = "system"; /* |--------------------------------------------------------------- | APPLICATION FOLDER NAME |--------------------------------------------------------------- | | If you want this front controller to use a different "application" | folder then the default one you can set its name here. The folder | can also be renamed or relocated anywhere on your server. | For more info please see the user guide: | http://codeigniter.com/user_guide/general/managing_apps.html | | | NO TRAILING SLASH! | */ $application_folder = "application"; /* |=============================================================== | END OF USER CONFIGURABLE SETTINGS |=============================================================== */ /* |--------------------------------------------------------------- | SET THE SERVER PATH |--------------------------------------------------------------- | | Let's attempt to determine the full-server path to the "system" | folder in order to reduce the possibility of path problems. | Note: We only attempt this if the user hasn't specified a | full server path. | */ if (strpos($system_folder, '/') === FALSE) { if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE) { $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder; } } else { // Swap directory separators to Unix style for consistency $system_folder = str_replace("\\", "/", $system_folder); } /* |--------------------------------------------------------------- | DEFINE APPLICATION CONSTANTS |--------------------------------------------------------------- | | EXT - The file extension. Typically ".php" | FCPATH - The full server path to THIS file | SELF - The name of THIS file (typically "index.php") | BASEPATH - The full server path to the "system" folder | APPPATH - The full server path to the "application" folder | MEDIAPATH - The full server path to the "media" folder */ define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION)); define('FCPATH', __FILE__); define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); define('BASEPATH', $system_folder.'/'); define('MEDIAPATH', dirname(__FILE__).'/media'); if (is_dir($application_folder)) { define('APPPATH', $application_folder.'/'); } else { if ($application_folder == '') { $application_folder = 'application'; } define('APPPATH', BASEPATH.$application_folder.'/'); } /* |--------------------------------------------------------------- | LOAD THE FRONT CONTROLLER |--------------------------------------------------------------- | | And away we go... | */ require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; /* End of file index.php */ /* Location: ./index.php */ 

Имейте в виду, что я случайно захватил это из одного из наших проектов CI, чтобы его можно было настроить – я действительно не помню – но это определенно не пусто.

Кроме того, config:

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

и htaccess:

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