skip to Main Content

Here is my URL with SEO Title

http://prdemos.com/Web/2015/assetsrecovered/index.php/pages/page?seo=ar-about-us

i want to change it in

http://prdemos.com/Web/2015/assetsrecovered/ar-about-us

index.php/pages/page?seo= this portion should be removed.

4

Answers


  1. Chosen as BEST ANSWER

    First of All i set config.php

    $config['index_page'] = ""; 
    

    And

    $config['uri_protocol'] = 'PATH_INFO';
    

    After that in routes.php

    $route['default_controller'] = "welcome";  // Default Controller
    $route['pages/([a-zA-Z-0-9.&_]+)'] = "pages/index/$1";
    $route['404_override'] = '';
    

    I called the dynamic menu with slug (or SEO title), in my header.php

    <?php
    foreach($menu as $menu_item){
    ?>
    <li>
    <a href="<?php echo base_url();?>pages/<?php echo $menu_item['seo'];?>">
    <?php echo $menu_item['name'];?>
    </a>
    </li>
    <?php
    }
    ?>
    

    My Controller is pages.php

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    class Pages extends CI_Controller {
    
        public function index($seo='')
        {
          $this->load->model('MPages');
          $data['seo']=$this->MPages->get_seo_by_page_slug($seo)->result();
          // Loading Common Views
            $this->load->view('header',$data);
            $this->load->view('topbar',$data);
            $this->load->view('mypage_view',$data);
        }
    }
    

    Finally i am getting these URLs

    http://mysitelive/pages/ar-about-us
    http://mysitelive/pages/ar-services
    

  2. Remove index.php from url using .htaccess like this,

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

    To remove remaining part, use routes.php

    $route['{default_controller}/{default_method}/(:num)'] = "{original_controller}/{original_method}/$1";
    
    Login or Signup to reply.
  3. to remove index.php

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    </IfModule>
    
    Login or Signup to reply.
  4. <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
      ErrorDocument 404 /index.php
    </IfModule>
    

    This .htaccess file will allow to write links without index.php in url, but it will still look like:
    http://prdemos.com/Web/2015/assetsrecovered/pages/page?seo=ar-about-us

    You need to modify your routes and controller to remove ?seo=.

    In controller your action should be public function page($seo) something like this and route should be $route['pages/page/(:any)'] = "pages/page/$1"; and then in controller action function change your $_GET['seo'] to $seo.

    And after this you can access your page like:
    http://prdemos.com/Web/2015/assetsrecovered/pages/page/ar-about-us

    If you want to remove /pages/page then you can add this to your routes.php:
    $route['(:any)'] = "pages/page/$1. But use this with precautions, because wrong placement in routes file can prevent other routes from working

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