douzhen9428
2016-02-05 03:50
浏览 235
已采纳

CodeIgniter从url中删除index.php

I know this question has been asked a number of times. However, I still wasn't able to get rid of index.php url. It is preventing me to access my controller directly.

I am current using CodeIgniter 2.2.2.
And the following is my .htaccess file:

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

application/config:

//  Find the below code

$config['uri_protocol'] = "AUTO"

//  Replace it as

$config['uri_protocol'] = "REQUEST_URI" 

Any Idea? Thanks in advance for your time.

图片转代码服务由CSDN问答提供 功能建议

我知道这个问题已被多次询问。 但是,我仍然无法摆脱 index.php网址。 它阻止我直接访问我的控制器。

我目前正在使用 CodeIgniter 2.2.2
以下是我的。 htaccess 文件:

 &lt; IfModule mod_rewrite.c&gt; 
RewriteEngine On 
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{REQUEST_FILENAME}!-d \  nRewriteRule ^(。*)$ index.php / $ 1 [L] 
&lt; / IfModule&gt; 
   
 
 

application / config: < / p>

  //找到下面的代码
 
 $ config ['uri_protocol'] =“AUTO”
 
 //将其替换为
 
 $ config [  'uri_protocol'] =“REQUEST_URI”
   
 
 

任何想法? 提前感谢您的时间。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

8条回答 默认 最新

  • dongxin8392 2016-02-15 07:54
    已采纳

    Finally fixed my problem. I would like to share my answer to all of you. I am currently using a mac, my rename my .htaccess file into htaccess.txt And had the following code inside htaccess: RewriteEngine On

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    #RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
    
    ErrorDocument 404 /index.php
    

    Then make sure Apache is reading the htaccess.txt file by doing this:

    1. Uncomment the following line on your httpd.conf

    2. Go inside to the extra/httpd-default.conf file and change this line of code: AccessFileName .htaccess to AccessFileName htaccess.txt

    3. Restart Apache server

    4. Inside your config, make sure to leave 'base_url' empty (index page can still be there, doesn't matter). And $config['uri_protocol'] = 'REQUEST_URI';

    Hope this can help others out there!

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duanfu2562 2016-02-05 03:59

    Use below code in your .htacess

       DirectoryIndex index.php
        RewriteEngine on
        RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
    
    评论
    解决 无用
    打赏 举报
  • dongyuan1870 2016-02-05 04:00

    try this..

    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]
    
    评论
    解决 无用
    打赏 举报
  • dongmi5607 2016-02-05 04:03

    i had the same problem before. this is what i did

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

    then go to config.php and remove the index.php

    $config['index_page'] = 'index.php';
    //change it to
    $config['index_page'] = '';
    
    评论
    解决 无用
    打赏 举报
  • doutou7286 2016-02-05 04:09

    This worked for me.

    RewriteEngine on 
    RewriteCond $1 !^(index.php|resources|robots.txt) 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    
    评论
    解决 无用
    打赏 举报
  • dongyang7152 2016-02-05 04:53

    If your using wamp make sure you have apache mod rewrite enabled.

    This htaccess is good for wamp or xampp

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

    Make sure it is placed on the main directory.

    $config['index_page'] = '';
    
    评论
    解决 无用
    打赏 举报
  • dongshan4316 2016-02-05 05:40

    on your .htaccess

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

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

    worked for me

    评论
    解决 无用
    打赏 举报
  • dsqdpn31467 2016-02-05 06:04

    From the CI User Manual:

    Index.php file will be included as default in your URLs.

    Example:

    example.com/index.php/controller
    

    How can you change?

    You can use rewrite rule in .htaccess for removing index.php from the URLs

    Example from User Guide:

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

    Using the "negative" method in which everything is redirected except the specified items.

    One last thing make you are using index_page as empty location application/config/config.php:

    $config['index_page'] = '';
    

    In last if you are still facing issue change uri_protocol AUTO to REQUEST_URI.

    $config['uri_protocol'] = "REQUEST_URI";
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题