简体   繁体   中英

Codeigniter specific URL rewriting

In one of my CI application I got a controller called movies in which I am showing details of a movie, its URL looks like

http://localhost/movies/index/12/Movie-Name

here 12 is the movie id which is used for fetching values from db and movie name, which is using for SEO URL.

I would likes to rewrite this URL to

http://localhost/12-Movie-Name

I already removed index.php from my application using http://codeigniter.com/wiki/mod_rewrite

Please help Thanks in advance

Maybe try

RewriteRule    ^/([0-9]+)\-([^/]+?)/?$  /movies/index/$1/$2

Although it may cause problems with other parts of your Codeigniter application.

or you can add this to Codeigniter router

$router['/(:any)'] = 'movies/index/12/$1';

but your movies id need to set as string with title.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM