php - .htaccess 不工作 - CodeIgniter

标签 php apache .htaccess codeigniter

我尝试在 Ubuntu 服务器上托管一个 CodeIgniter 网站。

所有其他网站都运行良好,没有任何问题(服务器包含 WordPress 和 Laravel 应用程序)。但是这个特定的 CodeIngniter 网站没有使用 .htaccess 文件。我花了一天时间来解决这个问题,但没有成功。

这是详细信息。

网站网址结构:http://example.com/website_name

.htaccess 文件

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

虚拟主机入口

<VirtualHost *:80>
    ServerName example.com
    ServerAlias example.com
    DocumentRoot "/var/www/example.com"
    <Directory "/var/wwww/example.com">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride ALL
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

CodeIgniter 配置文件

$config['base_url'] = 'http://example.com/website_name/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

当我尝试访问该网站时,输出如下,

Not Found
The requested URL /website_name/test was not found on this server.

但是如果我添加 index.php,该网站可以正常运行。试了很多方法都没用。

最佳答案

试试这个 .htaccess

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    Options -Indexes
    RewriteEngine On
    RewriteBase /website_name/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond $1 !^(index\.php)
    RewriteRule ^(.*)$ index.php [L]

</IfModule>

关于php - .htaccess 不工作 - CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33958887/

相关文章:

linux - Linux 上最适合用户私有(private)文件夹的文件夹分布是什么?

php - 如何根据查询字符串中的匹配使用 SetEnvIf?

php - 输入类型文件上传的最大文件数

php - Yii 框架单选按钮列表

javascript - angularjs http + script7002 : xmlhttprequest: network error 0x80070005, 访问被拒绝

apache - 如何使我的 .htaccess 强制使用 https,但仅适用于一个目录(同时保留 ExpressionEngine 和基于无 www 的规则)

php - WordPress SEO 友好的 url 是否可以在不使用 htaccess 的情况下工作?

php - 如何使用 PHP 列出按字母顺序排序的目录中的所有文件?

php - jQuery - click() 在附加到在 PHP 中创建的 anchor 时不起作用

php - 使用未定义常量 STDOUT - 假定为 'STDOUT'