2

I am using a multiple methods in one class.I want to only remove index from url only and other remain same;

www.mysite.com/blog/index
www.mysite.com/blog/index/one/two
www.mysite.com/blog/myblog
www.mysite.com/blog/data_load/one/two
3
  • 1
    use route it will help you to rewrite the url and it will link to the particular method into the class Commented Mar 29, 2018 at 13:18
  • 1
    You need to write rules in routes.php naveedramzan.com/codeigniter-url-rewriting Commented Mar 29, 2018 at 13:18
  • I try naveedramzan.com/codeigniter-url-rewriting but when i pass parameter (string) after blog redirect on 404 page Commented Mar 29, 2018 at 13:38

4 Answers 4

3

Hope this will help you :

in route.php

$route['blog'] = 'blog/index';

Make sure :

in your config file set this :

 $config['base_url'] = 'http://localhost/foldername/';

 $config['index_page'] = '';
Sign up to request clarification or add additional context in comments.

1 Comment

@paradeep this answer is not enough to answer his question! it will redirect all url starting with blog to blog/index method!
2

Try this in application/config/routes.php:

$route['blog/myblog']                   = 'blog/myblog';
$route['blog/data_load/(.+)/(.+)']      = 'blog/data_load/$1/$2';
$route['blog']                          = 'blog/index';
$route['blog/(.+)']                     = 'blog/index/$1';
$route['blog/(.+)/(.+)']                = 'blog/index/$1/$2';

Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.

4 Comments

I try but when i pass parameter (string) after blog redirect on 404 page
it depend of which number of parameters you need, if you need 1 parameter you must add $route['blog/(.+)'] = 'blog/index/$1/';
Hi Louk!!How to pass unlimited parameters in route without index??
@usman in this case check this link: stackoverflow.com/questions/9455374/…
0

you need to set route for that.

set route in your application/config/routes.php file

$route['project/user/id/(:any)'] = 'project/user/index/id/$1';

Comments

0

You can also use a .htaccess file to handle that. Create a .htaccess file and paste this code in it

<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
   RewriteRule ^(.*)$ 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.

    ErrorDocument 404 /index.php
</IfModule>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.