php - 如何从 UBUNTU 中的 codeigniter 中删除 index.php

标签 php .htaccess codeigniter mod-rewrite

<分区>

我知道这个问题已经被问过了,我尝试了所有这些但仍然无法从 url 中删除 index.php。 这是我的详细信息

Ubuntu 12.10
PHP : 5.4.6
Mod_rewrite in on
CI verson: 2.1

.htacess 看起来像:

RewriteEngine On
RewriteBase /projectname

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

我也看了下面的链接,但没有运气.. Cannot remove index.php from url CI based site

How to remove "index.php" in codeigniter's path

我的“/etc/apache2/sites-available/default”是这样的:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None 
        </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

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

感谢任何帮助!!

最佳答案

第 1 步:

在htaccess文件中添加

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

第 2 步:

删除 codeigniter 配置中的 index.php

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

第 3 步:

允许在 Apache 配置(命令)中覆盖 htaccess

sudo nano /etc/apache2/apache2.conf

并编辑文件并更改为

AllowOverride All

对于 www 文件夹

第 4 步:

启用 apache mod 重写(命令)

sudo a2enmod rewrite

第 5 步:

重新启动 Apache(命令)

sudo /etc/init.d/apache2 restart

关于php - 如何从 UBUNTU 中的 codeigniter 中删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16556915/

相关文章:

php - 如何通过其自己的加密值更新每一行

php - 我应该在 Ruby on Rails 中重写我的 Codeigniter/PHP 应用程序吗?为什么?

php - Sqlite3 和 PDO 问题与 ORDER BY

php - 在 Laravel 5.2 中将请求对象转换为 JSON

php - 如何在另一台本地计算机上访问我的 Wamp 服务器

.htaccess - htaccess 永久重定向抛出内部服务器错误

php - mysql 一个字段按不同的优先级排序

php - 在 Azure 中创建 blob 时遇到的问题

apache - Htaccess - 如果未设置 env var 则跳过重定向

apache - 解释htaccess规则?