开发者

Clean url for SEO in Codeigniter

How to remove the controller/method for cleaner URL in codeIgniter.

The original url is below

www.mydomain.com/controllers/method/variable

and I want my url look like this

www.mydomain.com/variable

or

www.mydomain.com/friendly-url-description/5

where 5 is key or id of the table, and the friendly-url-description is description of开发者_高级运维 the value. please help guys.


One way is to modify the file /system/application/config/routes.php like for instance:

<?php
$route['friendly-url-description/(:any).html'] = 'controllers/method/$1';

http://codeigniter.com/user_guide/general/routing.html


Use CodeIgniter Routing.

Try using regular expressions, for this one:

www.mydomain.com/controllers/method/variable

www.mydomain.com/variable

try using if it's just string:

$route['(a-zA-Z)'] = 'controllers/method/$1';

for this one:

www.mydomain.com/friendly-url-description/5

try using:

$route['(a-zA-Z)/(0-9)'] = 'controllers/method/$1/$2';


Use the URI Routing.

http://codeigniter.com/user_guide/general/routing.html


Using .htaccess you can rewrite the url to whatever you like.

http://corz.org/serv/tricks/htaccess2.php

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(\w+)& controllers/method/$1

I haven't tested that, but it should make the address www.mypage.com/var referr to www.mypage.com/controllers/method/var

The shorthand "\w" means "any character or number", that is a-z, A-Z, 0-9 and underscore. The + means "once or more". Look up a regular expression tutorial to learn more.

Good luck :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜