Welcome Guest, Not a member yet? Register   Sign In
Change Incoming URL Before Page Proccessed on Load?
#1

[eluser]markanderson993[/eluser]
Hello Codeigniter experts! I hope my question isn't too difficult. In essence, my site is using a jQuery Navigation system that does the following, say this happens.

1. Go to www.mysite.com (url is www.mysite.com)
2. Click profile tab (url becomes www.mysite.com/#/profile)
3. Click forums tab (url becomes www.mysite.com/#/forums)
And so on..

Now this is working perfectly displaying the correct controllers. However, what if someone was coming into the site with this in their browser url:

1. User types in www.mysite.com/#/profile in their browser and hits enter
2. The browser goes to the site
3. Can I detect that a /#/ occurs after the base_url() and a rewrite the url into www.mysite.com/profile before the site is rendered?


Any help would be greatly appreciated!
Thank you in advance for any assistance you may be,

Mark Anderson
#2

[eluser]theprodigy[/eluser]
so, do you want to change the url (redirect them from mysite.com/#/profile to mysite.com/profile), or just make CI think that it is without the # (leave them at mysite.com/#/profile, but render as if mysite.com/profile)?
#3

[eluser]markanderson993[/eluser]
Thanks for the speedy reply Smile

Both your solutions would arrive at the same result, allowing codeigniter to process the URL in the way it wants.
If either solution code be converted to code, either would work. My personal preference would air on the side of converting mysite.com/#/profile to mysite.com/profile immediately before the page is processed.

The only reason I say this is because this is exactly what Reverbnation does. For example, when you try this link
http://www.reverbnation.com/#/main/overview_label
The page becomes http://www.reverbnation.com/main/overview_label

Mark Anderson
#4

[eluser]theprodigy[/eluser]
In the case of actually redirecting them, do some research on htaccess and 301 redirects.
In the case of just making CI render as if it wasn't there, look into CI's URI routing (application/config/routes.php)

The URI routing would be easier in my opinion, but will not give the redirect you are looking for.
#5

[eluser]markanderson993[/eluser]
Thank you again for your speedy reply.

I looked into the routes.php file under application/config, it contains statements pertaining to the default controller and scaffolding.

How would I go about altering this to "re-route" an incoming url?
Would I need an if statement? If so, (no pun intended haha) what code would I need to include?

Thanks for your help!
Mark Anderson
#6

[eluser]markanderson993[/eluser]
Perhaps, should I create a pre-system hook do what would be done in a .htaccess mod_rewrite?
#7

[eluser]theprodigy[/eluser]
if you read the URI routing section of the user_guide, you will see that you can use this section to re-route incoming requests.

from the user guide:
Quote:Here are a few routing examples:
Code:
$route['journals'] = "blogs";

A URL containing the word "journals" in the first segment will be remapped to the "blogs" class.
Code:
$route['blog/joe'] = "blogs/users/34";

A URL containing the segments blog/joe will be remapped to the "blogs" class and the "users" method. The ID will be set to "34".
Code:
$route['product/:any'] = "catalog/product_lookup";




Theme © iAndrew 2016 - Forum software by © MyBB