使用Wamp Server从Codeigniter 3中的url中删除index.php时遇到问题。我在文件config.php(project_folder / application / config / config.php)
中进行了更改$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和错误抛出
abc.local/controllername
Not found
The requested URL /controllername/ was not found on this server.
谢谢!
答案 0 :(得分: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';
答案 1 :(得分: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>