CodeIgniter removing index.php from url

前端 未结 30 1400
[愿得一人]
[愿得一人] 2020-11-21 11:51

My current urls look like this [mysite]index.php/[rest of the slug].
I want to strip index.php from these urls.

mod_rewrite

相关标签:
30条回答
  • 2020-11-21 12:04

    Only three steps are require to remove index.php from url in Codeigniter

    1) Create .htacess file in parallel to application holder and just copy past the following code:

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

    2) Change $config['index_page'] to blank in config.php in application folder as below:

    $config['index_page'] = '';
    

    3) Enable “rewrite_module” of apache.

    Restart your apache and its done.

    Details : http://sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

    0 讨论(0)
  • 2020-11-21 12:07
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]
    

    use

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

    if you have url in this order site.com/index.php/class/method/id

    NB:remove index.php in config.php should be config[index_page] = ""

    NB: notice the difference at the last line instead of $0 use $1

    0 讨论(0)
  • 2020-11-21 12:11

    try this RewriteEngine On

            # Removes index.php from ExpressionEngine URLs
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/$1 [L]
    </IfModule>
    
    0 讨论(0)
  • 2020-11-21 12:11

    if all the above solution not work then in your project folder their will be two files index.html and index.php, rename index.html to index_1.html and browse your project.

    0 讨论(0)
  • 2020-11-21 12:12

    Both development and production

        # Development
        RewriteEngine On
        RewriteBase /your_local_folder/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
        RewriteRule ^(.*)$ index.php/$1 [L]
    
        #Production PHP5 CGI mode
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
        RewriteRule ^(.*)$ index.php?/$1 [L]
    
    0 讨论(0)
  • 2020-11-21 12:13

    first of all you have to on the apache server rewrite engine on.this link will help you for that

    http://www.anmsaiful.net/blog/php/enable-apache-rewrite-module.html

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

    this will be your .htaccess file. now try it .this setting works for me.

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