[英]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.