skip to Main Content

i want to hide index.php and controller name from my codeignier url website
also i want to replace this term ?seo=test-product ad /test-product

i have mention my htaccess file below please guild me how to fix this issue i have tried many things none helps

 RewriteEngine On
 RewriteCond %{HTTPS} off [OR]
 RewriteCond %{HTTP_HOST} ^www. [NC]
 RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
 RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

2

Answers


  1. try this

    RewriteEngine on
    RewriteCond $1 !^(index.php|resources|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    
    Login or Signup to reply.
  2. first we adding (.htaccess)(it is only extention file) file extention in our project directory

    it is my project file directory location
    http://localhost/demoproject
    demoproject is my project name

    copy below code and create (.htaccess) file and paste it under (.htaccess) file
    these file create under project directory

    Options +MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
    
    # Disable Directory Browsing
    Options All -Indexes

    one more (.htaccess) file create into view folder

    copy below code and paste it under newly created (.htaccess) file

    <IfModule authz_core_module>
        Require all denied
    </IfModule>
    <IfModule !authz_core_module>
        Deny from all
    </IfModule>

    normally code controller file
    DemoController.php

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    class DemoController extends CI_Controller 
    {
    	public function index()
    	{
            $data['demo'] = 'hello world';
            $this->load->view('DemoView', $data);
    	}
    }	
    enter code here
    

    normally code our view file
    DemoView.php

    <!DOCTYPE html>
    <html>
    <head>
    	<title>demo</title>
    </head>
    <body>
          <h1>
          	<!-- $demo is the $data of object that defind our DemoController. -->
               <?php echo $demo ?>
          </h1>
    </body>
    </html>

    run localhost and only type localhost/project_name/controller_name

    here we use demoproject as project name and DemoController as controller name
    http://localhost/demoproject/DemoController

    if your code not execute then please comment

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search