How to remove “index.php” in codeigniter's path

后端 未结 27 1354
盖世英雄少女心
盖世英雄少女心 2020-11-22 07:17

How do I remove the \"index.php\" sticking out in every path in codeigniter somewhere in the center? I want clean non index.php-fied URLs?

相关标签:
27条回答
  • 2020-11-22 08:12

    i tested this on apache2 on many different hosting and it works great.

    use this htaccess

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

    be sure you have enabled mod_rewirte with a phpinfo();

    then do this in 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';
    

    if it doesn't works yet, try to change the $config['uri_protocol']='AUTO' to one of the listed inside application/config/config.php file on line 40/54:

    sometimes i used : REQUEST_URI instead of AUTO or "QUERY_STRING" for goDaddy hostings

    0 讨论(0)
  • 2020-11-22 08:14

    All above methods failed for me and then I found that I was not changing AllowOverride None to AllowOverride All in my virtual host file at /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>
    
         ...
    

    0 讨论(0)
  • 2020-11-22 08:14

    This will help you paste this code in application folder in .htacess file

    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 讨论(0)
  • 2020-11-22 08:15

    place a .htaccess file in your root web directory

    Whatsoever tweaking you do - if the above is not met - it will not work. Usually its in the System folder, it should be in the root. Cheers!

    0 讨论(0)
  • 2020-11-22 08:16

    Copy past following code in your .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 讨论(0)
  • 2020-11-22 08:17

    As an .htaccess file, a good option is to use the one provided by the 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]
    

    It's a well thought out .htaccess that just works.

    0 讨论(0)
提交回复
热议问题