[英]Codeigniter 3.1.6 - How to remove index.php from url
我正在研究 codeigniter 3.1.6。
我添加了 .htaccess 文件。 我也改变了base_url
路径到我的项目路径,删除index.php
从index_page
,改变了url_protocol
到REQUEST_URI
。
尽管如此,当我将 url 重定向到任何控制器方法时,它会抛出一个错误,如“ The page you requested was not found
”。
我还搜索并应用了不同的 .htaccess 但它不起作用。 如果我在 base_url 末尾添加/index.php
则它可以工作但它是错误的。 它应该可以在没有 index.php.Only 3.1.6 的情况下工作。
注意:codeigniter-3.1.4 工作正常,只有这个版本有问题
将文件夹名称CodeIgniter-3.1.6
更改为ci
将您的base_url
设置为
$config['base_url'] = 'http://localhost/ci/
使用这个.htaccess
RewriteEngine On
RewriteBase /ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
在 .htaccess 中使用此脚本
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ index.php?/$1 [L]
# If your root folder is at /mypage/test1/
RewriteRule ^(.*?)$ /mypage/test1/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
从config.php
删除index.php
$config['index_page'] = '';
1) 编辑 config.php
$config['index_page'] = 'index.php';
至
$config['index_page'] = '’;
2) 创建/编辑 .htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
1:在根目录而不是另一个项目文件夹目录中创建 .htaccess 文件。
2:编写或复制此代码并粘贴
`<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule>`
我希望这能正常工作。 进入配置文件并进行更改 $config['url_protocol']='auto';
附加提示:确保根文件夹中的 .htacces 不在 >application 文件夹中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.