2015-11-13 20 views
1

我在使用Wamp Server從Codeigniter 3中的url中刪除index.php時遇到問題。我在文件中的config.php(project_folder /應用/配置/ config.php文件)刪除codeigniter中的index.php與wamp不起作用

$config['base_url'] = ''; 
$config['index_page'] = ''; 
$config['uri_protocol'] = "REQUEST_URI"; 

更改,並創建應用程序文件夾的.htaccess文件同樣級別的書面

<IfModule mod_rewrite.c> 
# Turn on URL rewriting 
RewriteEngine On 

# If your website begins from a folder e.g localhost/my_project then 
# you have to change it to: RewriteBase /my_project/ 
# If your site begins from the root e.g. example.local/ then 
# let it as it is 
RewriteBase/

# Protect application and system files from being viewed when the index.php is missing 
RewriteCond $1 ^(application|system|private|logs) 

# Rewrite to index.php/access_denied/URL 
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L] 

# Allow these directories and files to be displayed directly: 
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums) 

# No rewriting 
RewriteRule ^(.*)$ - [PT,L] 

# Rewrite to index.php/URL 
RewriteRule ^(.*)$ index.php/$1 [PT,L] 
</IfModule> 

和rewrite_module代碼是關於我的虛擬主機代碼是

<VirtualHost *:80> 
    DocumentRoot "D:/work/project_Name/" 
    ServerName abc.local 
    <Directory "D:/work/project_Name/"> 
     Order Allow,Deny 
     Allow from all 
     Require all granted 
    </Directory> 
</VirtualHost> 

使用這些變化和代碼我的項目不是沒有的index.php和錯誤拋

運行210
abc.local/controllername 
Not found 
The requested URL /controllername/ was not found on this server. 

謝謝!

+1

閱讀本教程的http:// w3code。 in/2015/09/how-to-remove-index-php-file-from-codeigniter-url/ – Ricky

+0

上述問題已通過虛擬h ost文件httpd-vhosts.conf(C:\ wamp \ bin \ apache \ apache2.4.9 \ conf \ extra)。將「Order Allow,Deny」替換爲「Allow all」歡呼! –

回答

1

試試這個代碼在.htaccess文件

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

而且在config.php頁面設置$config['base_url'] ="http://localhost/project/"$config['index_page'] = '';$config['uri_protocol'] = 'AUTO';

+0

其不起作用 –

+0

點擊Wampserver並選擇apache-> httpd.conf並從#LoadModule rewrite_module modules/mod_rewrite.so中刪除#。最後重新啓動Wamp服務器 –

1

嘗試這些:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /folder_name_of_project/ 


    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 


    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 


    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond $1 !^(index\.php|images|stylesheets|javascript) 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    ErrorDocument 404 /index.php 
</IfModule>