我尝试在 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/