Codeigniter 3.1.6 - How to remove index.php from url

微笑、不失礼 提交于 2019-12-23 12:02:06

问题


I am working on codeigniter 3.1.6.

I added the .htaccess file. I also changed the base_url path to my project path, removed the index.php from index_page and changed the url_protocol to REQUEST_URI.

Still, while I am redirecting the url to any controllers method it throwing an error as 'The page you requested was not found.'

I also searched and applied different .htaccess but its not working. If I am addling /index.php at end of base_url then its working but its wrong though. It should work without index.php.Only 3.1.6 giving this issue.

note: codeigniter-3.1.4 is working properly only this version is giving an issue


回答1:


Change folder name CodeIgniter-3.1.6 to ci

Set your base_url to

$config['base_url'] = 'http://localhost/ci/

Use this .htaccess

RewriteEngine On
RewriteBase /ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]



回答2:


Use this script in .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>

Remove index.php from config.php $config['index_page'] = '';




回答3:


1) Edit config.php

 $config['index_page'] = 'index.php';

To

 $config['index_page'] = '’;

2) Create/Edit .htaccess file

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



回答4:


1:Create .htaccess file in root directory not another project folder directory.

2:write or copy this code and paste it

 `<IfModule mod_rewrite.c>
     RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L]
              <IfModule>`

I hope this will work properly. Go In Config file and make changed $config['url_protocol']='auto';




回答5:


Additional tip: make sure .htacces in the root folder not inside >application folder



来源:https://stackoverflow.com/questions/46608887/codeigniter-3-1-6-how-to-remove-index-php-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!