我已经研究了stackoverflow上的所有问题,以便从codeigniter中删除index.php,但我仍然无法做到。仅打开登录页面,但其余页面为空白。
我使用自己的ubuntu
linux服务器。
我的重写模块也开启了。我尝试了$config['uri_protocol']
所有可能的值。 AUTO, PATH_INFO, QUERY_STRING, ORIG_PATH_INFO
。
我的htaccess代码在这里
RewriteEngine on
AddType text/x-component .htc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
vhost文件在这里
DocumentRoot /home/black-sheep/black-sheep.org
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /home/black-sheep/black-sheep.org/>
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 /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
我的网站网址是
http://black-sheep.org/
这是我在index.php
上回显__FILE__
时的路径
/home/black-sheep/black-sheep.org/index.php
令人惊讶的是,没有index.php的同一台服务器上的wordpress网站运行良好,跟随htaccess。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
我也试过这个htaccess,但它对我不起作用。
请建议我的解决方案。 提前致谢
答案 0 :(得分:3)
我有同样的问题。我解决了。 您必须在站点的根目录中添加.htaccess文件
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
主要您必须在/etc/apache2/apache2.conf中更改网站配置。
搜索目录/ var / www /
更改 AllowOverride无 - &gt; AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
答案 1 :(得分:2)
How to remove index.php in localhost(Ubantu) using codeigniter
sudo nano /etc/apache2/apache2.conf
write this code below.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
within codeigniter framework config/config.php
In application/config/config.php change:
$config['index_page'] = 'index.php';
to:
$config['index_page'] = '';
$config['base_url'] = 'http://localhost/code_test';
make .htaccess file main folder directory
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
答案 2 :(得分:1)
尝试此解决方案。
将以下代码粘贴到.htaccess文件中并将其移至codeigniter文件夹
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
答案 3 :(得分:1)
我遇到了同样的问题,但能够纠正它。我正在给你完整的指导。按照一步一步..
首先通过输入以下命令检查是否从终端启用了mod_rewrite:
sudo a2enmod rewrite
然后打开位于下面提到的目录中的文件apache2.conf
/etc/apache2/apache2.conf
在文件中找到<Directory /var/www/>
,然后将AllowOverride None
更改为AllowOverride All
如果不允许您保存文件,则表示该目录没有所需的权限。所以请通过运行以下命令给出。
sudo chmod -R 777 /etc/apache2/
然后保存文件。
现在编写.htaccess
文件并通过下面的代码保存文件。
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
然后通过以下命令重启您的apache服务
sudo service apache2 restart
希望它会起作用......