Welcome Guest, Not a member yet? Register   Sign In
Help for Custom URL
#1

[eluser]weblizzer[/eluser]
Hi Guys,

I'm trying to develop a website using CI. But I found this problem which I can't determine how i can solve this but maybe you can help me.

How can i achieve this things

www.example.com/your-url
www.example.com/about-us
www.example.com/contact-us

Note: that this each have different controllers, so I want to achieve this url.

Thanks in advance
#2

[eluser]Đaяк Đaηтє[/eluser]
I'm not completly sure, but you can use the routes to catch the url's and redirectit to the appropiate controller, or maybe yo can use .htaccess file with Rewrite Rules.

The routes.php file lets you remap URI requests to specific controller functions. For example, you may have a controller named site with a function named index . The URI for this controller/function combination might be :
Code:
http://www.example.com/site/index
Furthermore, if your site controller had a pages function that accepted a numeric ID for database lookup, the URI might look like this:
Code:
http://www.example.com/site/pages/4
In some cases, you might want to remap one or more of these default routes. For example, the second example might be better displayed as this:
Code:
http://www.example.com/about_us/
In that case, your routes.php file would contain a rule like this:
Code:
$route[‘about_us’] = “site/pages/4”;
For right now, though, this kind of manipulation falls under “ advanced usage, ” so don ’ t worry too much about it. However, please do note that this kind of thing is possible. Also, be aware that two “ reserved routes ” exist: default_controller and scaffolding_trigger.
Code:
$route[‘default_controller’] = “welcome”;
The default_controller route tells CodeIgniter which controller should be loaded if no controller is identified.

"Professional CodeIgniter"
#3

[eluser]weblizzer[/eluser]
thanks for your replay anyway this is how i try to do it

domain.com/about-us = domain.com/aboutus
domain.com/contact-us = domain.com/contactus

Now when I try to declare this
Code:
$route['([a-z\-])+'] = str_replace('-','','$1');

But still it doesn't work. Or is theire a preg_replace function in htaccess? not sure lol.

Hehehh thanks in advance
#4

[eluser]Colin Williams[/eluser]
Quote:
Code:
$route['([a-z\-])+'] = str_replace('-','','$1');

$1 has no context when used like that. It literally just means '$1'

You're better off overloading the Router class and doing something custom
#5

[eluser]weblizzer[/eluser]
okay anyway I just got it my own... I just make some tweaks on the router.php and it work.Smile
#6

[eluser]Đaяк Đaηтє[/eluser]
Yo need to use .htaccess file to adjust the url, I give you the next example:
Adjusting URLs.
Problem:We Want to Rewrite Path Information to a Query

We have a URL that looks like this:
Quote:http://example.com/vegetables.php?carrots
. We’d like it to look like this instead:
Quote:http://example.com/vegetables/carrots
.

Solution
Code:
RewriteEngine On
RewriteRule ^/vegetables/(.*) /vegetables.php?$1 [PT]

Discussion
The effect of this rule will be that anything appearing after /vegetables/ will be put into the query string. This is the simplest possible example of this class of rewrites, and it’s almost always simpler than what you actually wanted to do. But it’s a good starting place
to see how you might approach something like this.
As always, if we are in fact using this in an .htaccess file, we need to remove the leading slash on the rule. It would therefore become
Quote:RewriteRule ^vegetables/(.*) vegetables.php?$1 [PT]
.




Theme © iAndrew 2016 - Forum software by © MyBB