2

I want to clear my url with codeigniter, I have these types of urls: www.ggg.com/index.php/page/8/name.html and I want to trasform these like www.ggg.com/index.php/name.html or www.ggg.com/name.html

Is this possible modifying the file route.php?

2 Answers 2

3

Actually to get rid of the index.php you need to edit out the index.php file from config.php (in your config folder inside application).

.htaccess for clean urls:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

and to get rid of the .html just eliminate that 'suffix' again in the config/config.php file.

That should be all you need, the .html ending is just for show

As far as turning something like page/8/name into name, I would think twice about how that would work, your page or 8 most likely mean something, so your name would have to have code making it unique. My guess is that page = 8 is the value, and the name is just for the friendly url look.

Sign up to request clarification or add additional context in comments.

3 Comments

I agree about being careful about routing but the question was asking whether or not it was possible - which it is. We weren't asked if we thought it was a good idea!!
yes 8 is a id and name is something just for firendly url look
@Pierluigi Ballatore - If that is the case as I assumed, make sure to test if this type of change in URI will not upset the traversal of your website/app.
2

Edit the routes.php file and add the line: $route['name'] = "page/8/name"; This is all explained in the docs: http://codeigniter.com/user_guide/general/routing.html To remove the index.php you will need a .htaccess file. There is an example in the ci docs or google it and you will find loads of tutorials. I'm sure there are even some examples here.

2 Comments

there is a problem when I write this rule in route.php: $route['page/index/:num/:any']='$2' it doesn't work, codeigniter said me "Page not fuond " when I write the url "www.ggg.com/index2.php/page/index/8/name.html"
You've got it the wrong way around. The array key is the URL that you want to see, in your case www.ggg.com/name and the array value is the controller/method that you actually want to use. Your problem is that the method you want to use requires an id as a parameter that is not fixed. The only thing I could suggest is to store (maybe temporarilly) the id in a session and then retrieve it when you need it. That way you could route "name" to "page/index" and it should all work for you.

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.