Welcome Guest, Not a member yet? Register   Sign In
How do you remove the controller from the URL?
#1

[eluser]learning_php[/eluser]
Hi,

My url's are currently :
http://localhost/wedding-site/homepage/X but I want them to look like this:
http://localhost/wedding-site/X. I have looked at the routes.php file but I am unsure what I need to do?

Thanks
#2

[eluser]Dam1an[/eluser]
Code:
$route['homepage/(:any)'] = "$1";

That should do it
#3

[eluser]learning_php[/eluser]
Hi,

After putting that in the routes I get a 404 error

Thanks
#4

[eluser]Dam1an[/eluser]
Sorry, my bad, got it the wrong way round, it should be
Code:
$route['(:any)'] = "homepage/$1";
#5

[eluser]learning_php[/eluser]
Hi,

I am still getting http://localhost/wedding-site/homepage/X

Thanks
#6

[eluser]Dam1an[/eluser]
When do you get that? When you go to the root of the site? Click a link, or even when you manually put the URL to http://localhost/wedding-site/X?
#7

[eluser]learning_php[/eluser]
Hi,

It seems that as my link was
Code:
<?= anchor('homepage/info','Information');?>
it added the homepage into the URL so I changed the link to just
Code:
<?= anchor('/info','Information');?>

Thanks for the help
#8

[eluser]Dam1an[/eluser]
That would make sense, I thought you where getting the homepage in there when you just went to the homepage lol
And I don't think it makes a difference, but you don't need the '/' for the start fof your anchor
#9

[eluser]learning_php[/eluser]
Thanks for that. But I have another controller that now gets a 404 error is there any reason for this?

I dont link to this but type in the url.
#10

[eluser]Dam1an[/eluser]
Ah, should have seen that coming
Basically, it matches the rule in the route file, so its trying to route it to homepage/fuction, and I'm guessing you don't have a function with that name in the homepage controller?

Are you trying to access the function in the second controller with or without the controller name in the URL?

You'll either have to manually specify each route, or consolidate the controllers into one
Or use some clever Regex (which you'd have to look up)




Theme © iAndrew 2016 - Forum software by © MyBB