我有个问题。我需要从 CodeIgniter 框架中的 URL 中删除 index.php。任何人都可以帮助我吗?
问问题
652 次
3 回答
2
对于 lighttpd:
启用 mod_rewrite 模块并在您的 lighttpd.conf 中设置它
server.document-root = "/var/www/ci/",
url.rewrite-once = (
"/(.*)\.(.*)" => "$0",
"/(css|files|img|js|stats|user_guide)/" => "$0",
"^/([^.]+)$" => "/index.php/$1"
)
于 2014-05-25T17:15:12.347 回答
0
要避免 codeigniter url 中的“index.php”,请按照以下步骤操作。
1.从system/application/config目录打开config.php并替换
$config['index_page'] = “index.php”
by
$config['index_page'] = “”;
2.在 CodeIgniter 根目录(系统目录所在的位置)创建一个“.htaccess”文件,使用您喜欢的文本编辑器打开该文件,写下以下脚本并保存:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
3.在某些情况下,uri_protocol 的默认设置不能正常工作。要解决这个问题,只需更换
$config['uri_protocol'] = “AUTO”
by
$config['uri_protocol'] = “REQUEST_URI”
从系统/应用程序/config/config.php
于 2014-05-25T19:38:33.857 回答
0
您只需要在项目文件夹中创建 .htaccess 文件并写入:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
#And You don't need to define in base_url in config file:
$config['base_url'] = '';// blank it.
我希望你明白..
于 2015-06-11T12:12:59.083 回答