[英]CodeIgniter Removing index.php using .htaccess file
使用.htaccess文件在CodeIgniter中删除index.php对我不起作用。 我尝试了以下代码,尽管无法正常工作。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
</IfModule>
我尝试了这个http://firstcode.info/codeigniter-removing-index-php-from-url/ 。 但是不起作用,但是它可以在我的本地主机上工作。 我也编辑了httpd.config文件,但是没有用。 请帮我。
第1步
打开文件夹“application/config”
然后打开文件“config.php“.
在config.php file.
找到并替换以下代码config.php file.
找到下面的代码
$config['index_page'] = "index.php"
replace with the below code
$config['index_page'] = "
第2步
在.htaccess文件中编写以下代码
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
步骤3
“application/config/config.php“,
然后查找并替换以下代码
找到下面的代码
$config['uri_protocol'] = "AUTO"
replace with the below code
$config['uri_protocol'] = "REQUEST_URI"
您提到的代码是正确的。
您必须修改apache2.conf(/etc/apache2/apache2.conf-它是我的服务器路径),检查您的路径。
找到此罪魁祸首"AllowOverride None"
和/var/www/
或/var/www/html
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
更新到
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
不要忘记sudo service apache2 restart
试试这个代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
在我的config.php文件中,我有以下设置。
$config['index_page'] = "";
$config['uri_protocol'] = "PATH_INFO";
如果使用localhost或domainname.com,请尝试在config.php中也更改基本URL。
$config['base_url'] = 'http://localhost/'; // localhost
要么
$config['base_url'] = 'http://domainname.com/'; // domainname.com
添加.htacess
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$
从config.php
$config['index_page']
中删除“ index.php”(保留空白值)
并修复项目文件夹的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.