Jak usunąć " indeks.php " w ścieżce codeigniter

Jak usunąć "index.php" wystające w każdej ścieżce w codeigniter gdzieś w centrum? I want clean non index.php-fied URLs?

Author: OrangeRind, 2009-09-18

27 answers

Jeśli używasz Apache place a .plik htaccess w katalogu głównym zawiera:

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

Kolejna dobra wersja znajduje się tutaj:

Http://snipplr.com/view/5966/codeigniter-htaccess/

 90
Author: Sean Vieira,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-18 15:53:45

Miałem duże problemy z usunięciem indeksu.php. Z reguły .poniższy htaccess został przetestowany na kilku serwerach i ogólnie działa:

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

<Files "index.php">
AcceptPathInfo On
</Files>  

Jeśli nie poszczęści ci się z tym, następnym krokiem jest dostosowanie pliku konfiguracyjnego. Wypróbuj inne protokoły URI, np.

| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO

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

Jeśli nadal nie masz szczęścia, spróbuj zmienić regułę przepisywania, aby włączyć swój podfolder. Jest to często problem, jeśli używasz tymczasowego adresu URL na serwerze deweloperskim itd:

RewriteRule ^(.*)$ /subofolder1/subfolder2/index.php/$1 [L]  

Po prostu baw się tymi opcjami, jeden powinien działać. Upewnij się również, że plik indeksu jest ustawiony na:

$config['index_page'] = '';
Powodzenia!
 60
Author: jimbo2087,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-10-28 14:53:30

Mieć.plik htaccess w katalogu głównym aplikacji wraz z indeksem.plik php. (Sprawdź , czy rozszerzenie htaccess jest poprawne, BZ htaccess.txt nie działa dla mnie.)

I dodać następujące zasady do .plik htaccess,

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

Następnie znajdź następujący wiersz w aplikacji / config / config.plik php

$config['index_page'] = 'index.php';

Ustaw zmienną empty jak poniżej.

$config['index_page'] = '';
To jest to, zadziałało na mnie.

Jeśli to nie działa dalej spróbuj zastąpić następujące zmienna z tymi parametrami ('AUTO',' PATH_INFO',' QUERY_STRING',' REQUEST_URI 'i' ORIG_PATH_INFO') jeden po drugim

$config['uri_protocol'] = 'AUTO';
 31
Author: Shaolin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-21 09:58:00

Zajrzyj do pliku system\application\config\config.php, istnieje zmienna o nazwie index_page

Powinno wyglądać tak

$config['index_page'] = "index.php";

Zmień na

$config['index_page'] = "";

Następnie, jak wspomniano, należy również dodać regułę przepisywania do pliku .htaccess

Uwaga: w CodeIgniter v2 plik ten został przeniesiony z folderu systemowego do application\config\config.php

 21
Author: Re0sless,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-24 23:50:33

Wszystkie powyższe metody zawiodły i okazało się, że nie zmieniam AllowOverride None na AllowOverride All w moim pliku wirtualnego hosta na /etc/apache2/sites-available / default

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride All    <---- replace None with All
    </Directory>
    <Directory /var/www >
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All   <---  replace None with All
            Order allow,deny
            allow from all
    </Directory>

     ...

 9
Author: waqas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-15 02:53:44
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /codeigniter/index.php/$0 [PT,L]

Po zmianie RewriteRule .* indeks.php / $0 [PT, L]z nazwą folderu projektu "codeigniter".działa na mnie. Dzięki chłopaki za wsparcie.

 6
Author: Captain Sparrow,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-21 13:23:35

Krok 1 = >Umieść swoje.plik htaccess w folderze głównym, w którym istnieją foldery aplikacji i systemu.

Krok 2 = > Jeśli twoja ścieżka WWW za pomocą podfolderu jak - yourdomain.com/project/ - następnie użyj następującego kodu w pliku htaccess

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

Jeśli twoja ścieżka www używając katalogu głównego jak - yourdomain.com - następnie użyj następującego kodu w pliku htaccess

RewriteEngine on
RewriteBase    /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
 6
Author: vinod,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-06-20 09:12:55

Po prostu pomyślałem, że mogę dodać

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

Byłoby .htaccess i pamiętaj, aby edytować aplikację / konfigurację.zmienna php w następujący sposób:

Zastąp

$config['uri_protocol'] = “AUTO” 

Z

$config['uri_protocol'] = “REQUEST_URI”
 5
Author: Jefkine Kafunah,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-06 10:30:33
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
To musi zadziałać.. spróbuj
 5
Author: Ramaraju.d,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-15 12:46:55

Upewnij się, że włączyłeś mod_rewrite (nie miałem).
Aby włączyć:

sudo a2enmod rewrite  

Również zastąp AllowOverride None przez AllowOverride All

sudo gedit /etc/apache2/sites-available/default  

W końcu...

sudo /etc/init.d/apache2 restart  
Mój .htaccess is
RewriteEngine on  
RewriteCond $1 !^(index\.php|[assets/css/js/img]|robots\.txt)  
RewriteRule ^(.*)$ index.php/$1 [L]  
 4
Author: miguelitomp,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-29 14:12:52

Idealne rozwiązanie [testowane na localhost, jak również na prawdziwej domenie ]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
 4
Author: Abhishek Goel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-10 18:58:12

To jest an .htaccess dla jednego z moich projektów CI:

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

Ostatnia linia powinna dać ci to, czego potrzebujesz, chociaż możesz lub nie potrzebujesz '/ projectFolder ' w zależności od konfiguracji struktury folderów. Powodzenia!

 3
Author: Matthew Rapati,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-18 15:51:25

Użyj mod_rewrite zgodnie z Instrukcją w Ten samouczek Z CI wiki.

 3
Author: Ben S,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-18 15:52:19

Jako .plik htaccess, dobrym rozwiązaniem jest użycie tego dostarczonego przez Kohana Framework :

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
To dobrze przemyślane .htaccess, który po prostu działa.
 3
Author: laurent,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-11 15:48:47

Istnieją dwa sposoby rozwiązania indeksu.php w ścieżce url dla codeigniter

1: w config/config.php Zmień kod:

$config['index_page'] = 'index.php';

Do

$config['index_page'] = '';

2:Utwórz .htacess w ścieżce głównej jeśli nie został utworzony,skopiuj następujący kod: -

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

Zapisz go, a następnie sprawdź w konfiguracji Apache rewrite_module lub mod_rewrite jest włączona.Jeśli nie, to proszę włączyć. (Najlepsze Podejście)!

 3
Author: Devraj Gupta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-06 09:35:01

Jest to jeden z najciekawszych i najciekawszych projektów w Polsce.

Użyj tego htaccess

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

Upewnij się, że masz enabled mod_rewirte z phpinfo();

Następnie zrób to w config / config.php:

$config['index_url']    = '';
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';

Jeśli jeszcze nie działa, spróbuj zmienić $config['uri_protocol']='AUTO' na jeden z wymienionych w application/config/config.php pliku w linii 40/54:

Czasami używałem : REQUEST_URI zamiast AUTO lub "QUERY_STRING" dla hostingów goDaddy

 2
Author: itsme,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-26 17:20:46

W pliku \application\config\config.php znajduje się zmienna o nazwie index_page

Powinno wyglądać tak

$config['index_page'] = "index.php";

Zmień na

$config['index_page'] = "";

Następnie, jak wspomniano, musisz również dodać regułę przepisywania do pliku .htaccess w następujący sposób:

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

To działa dla mnie, mam nadzieję, że ty też.

 2
Author: glider,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-24 06:39:52

Jeśli jesteś na Linuksie i korzystasz z serwera apache2, może być konieczne obejście apache2.plik conf również obok zmian na .plik htaccess. Zapraszamy do zapoznania się z naszą ofertąconf .

Search Directory / var / www / Change AllowOverride None - > AllowOverride All

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory
 2
Author: rabin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-17 02:23:42

Miejsce a .plik htaccess w katalogu głównym

Jakiekolwiek modyfikacje - jeśli powyższe nie zostanie spełnione - nie zadziała. Zwykle jest w folderze systemowym, powinien być w katalogu głównym. Zdrowie!

 1
Author: foxybagga,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-03 12:18:40

Próbowałem wielu rozwiązań, ale to, co wymyśliłem, Jest Takie:

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots  \.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

To spowoduje usunięcie indeksu.php z adresu url zgodnie z wymaganiami.

 1
Author: codegeek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-14 11:53:05

Używam tych linii w pliku .htaccess, który umieszczam w katalogu głównym

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

Wtedy mogę uzyskać dostęp http://example.com/controller/function/parameter

Zamiast http://example.com/index.php/controller/function/parameter

 1
Author: Scorpion,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-14 13:50:30

To ci pomoże wklej ten kod w folderze aplikacji w .plik htacess

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

<Files "index.php">
AcceptPathInfo On
</Files>
<IfModule mod_php5.c>
  php_value short_open_tag 1
</IfModule>
 0
Author: Majid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-10 07:29:01

Ten zrobił mi całą magię:

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Mam nadzieję, że to pomoże!
 0
Author: bmnepali,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-04 06:21:15

Hi This one work me

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

Jak również to

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

Gdzie folder jest nazwą podfolderu, jeśli aplikacja codeigniter jest hostowana jako subdomena np. domainname / folder / index.php.

Mam nadzieję, że ci się uda. Dzięki.
 0
Author: lightup,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-18 13:05:55

Skopiuj poniższy kod w swoim .htaccess

RewriteEngine on
Options -Indexes
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
 0
Author: dev87,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-23 07:23:12
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Foldername of your ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
 0
Author: mohd jagir,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-11-15 18:24:57

Krok 1 :

Dodaj to do pliku htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 
#RewriteBase / 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [QSA,L] 
</IfModule>

Krok 2 :

Usuń indeks.php in codeigniter config

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

Krok 3 :

Zezwalaj na nadpisywanie htaccess w konfiguracji Apache (polecenie)

Zapraszamy do zapoznania się z naszą ofertąconf i edytuj plik i zmień na
AllowOverride All

Do katalogu www

Krok 4 :

Enabled Apache mod rewrite (Command)

Sudo A2enmod rewrite

Krok 5 :

Restart Apache (Command)

sudo /etc/init.d/apache2 restart
 0
Author: Shashank Saxena,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-08-23 06:43:38