【问题标题】:Removing index.php from CodeIgniter 3 URLs从 CodeIgniter 3 URL 中删除 index.php
【发布时间】:2015-09-28 12:05:36
【问题描述】:

我正在尝试从我的 CodeIgniter 3 URL 中删除 index.php。目前,我所有的 URL 都是这样的:

http://example.com/index.php/Controller/function

我希望它们看起来像这样:

http://example.com/Controller/function

我关注了以下文章和 Stack Overflow 帖子,但我找到的答案都没有对我有用:

我的目录结构设置如下:

  • /var/www/example
    • /应用程序
      • (标准 CodeIgniter 应用程序文件...控制器、模型、视图、配置)
    • /公共
      • /css
      • /js
      • /字体
      • /图片
      • index.php
      • .htaccess
    • /系统
      • 我没有接触过这个目录中的任何东西
    • .htaccess

/var/www/example/.htaccess 的内容:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

/var/www/example/public/.htaccess 的内容:

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

/var/www/example/application/config/config.php 的内容(根据我之前的阅读内容进行了修改):

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; /* have tried AUTO as well */

对于我的 Apache 服务器,mod-rewrite 已通过以下方式启用:

sudo a2enmod rewrite
sudo service apache2 restart

我的这个网站的虚拟主机文件是:

<VirtualHost *:80>
    ServerAdmin myemail@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

【问题讨论】:

    标签: apache .htaccess codeigniter


    【解决方案1】:

    将这些添加到您的虚拟主机文件并根据需要调整选项指令。

        <Directory />
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
    
        <Directory "/var/www/example/public">
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
    

    【讨论】:

      猜你喜欢
      • 2021-12-15
      • 2016-11-23
      • 2020-08-12
      • 2022-01-06
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2012-09-21
      相关资源
      最近更新 更多