首页 文章

我想从codeigniter url中删除index.php

提问于
浏览
0

我想从codeigniter url中删除index.php我到目前为止尝试的当前配置为零结果

文件夹结构:xampp \ htdocs \ Codeigniter \ application \ controllers \ olx \ olx.php xampp \ htdocs \ Codeigniter \ application \ views \ olx \ frmSignup

我的HTACCESS文件位于xampp \ htdocs \ Codeigniter.HTACCESS位置,其中包含以下内容.HTACCESS文件中的其他内容

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

使用phpinfo()启用mod_rewrite;

以下对config.php文件所做的更改

$config['base_url'] = 'http://mypc/olx';
$config['index_page'] = '';

当试图访问此网址时

http://mypc/codeigniter/olx/frmSignup i get 404 error

对routes.php所做的更改是

$route['default_controller'] = 'olx';
$route['olx/frmSignup']  = 'olx/frmSignup';

请帮助我想要在没有index.php的情况下访问我的应用程序 . 我正在使用Windows7在localhost上工作

5 回答

  • 0

    在我的虚拟主机文件中将AllowOverride None更改为AllowOverride All在ubuntu中的/etc/apache2/sites-available/000-default.conf中将更改AllowOverride无更改为AllowOverride我的虚拟主机文件中的所有内容位于/ etc / apache2 / sites-available / default Windows中的.conf

    <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>
    ....
    

    然后将此代码放在codeigniter的根文件夹中的.htaccess文件中

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

    它肯定会起作用 .

  • 0

    来自http://ellislab.com/codeigniter%20/user-guide/general/urls.html - 试试

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

    毕竟朋友说,你必须做另一件事(我想你是在localhost上做的):

    首先,仔细检查建议:然后转到Windows托盘,右键单击WAMP图标,然后单击它,转到Apache菜单,然后转到模块,然后检查rewrite_module以查看是否已选中,然后单击如果您发现它未经检查(意味着已禁用)以启用它 . 现在再试一次并报告......

  • 0

    您只需在根应用程序文件夹上创建.htaccess文件或编辑它(如果已有) . 以下.htaccess文件适合我 .

    .htaccess

    # BEGIN ci
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    RewriteCond ${REQUEST_URI} ^.+$
    RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
  • 1
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /Codeigniter
    
    #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 %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    

    所以不是olx,因为它是一个控制器,而不是一个文件夹

    在配置中

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

    在路上

    $route['default_controller'] = "olx";
    

    并将您的D:\ xampp \ htdocs \ Codeigniter \ application \ controllers \ olx \ olx.php移动到D:\ xampp \ htdocs \ Codeigniter \ application \ controllers \ olx.php

    和olx应该是这样的

    class olx extends CI_Controller {
    
    
     public function __construct()
       {
           parent::__construct();
    
     }
    
    
    public function index()
    {
    
        echo "test";
        // or $this->load->view('olx/overview.php', $data);
    
    }
    
    }
    

    并尝试localhost / codeigniter /或localhost / codeigniter / olx

相关问题