# Character in the url


I want to format urls for a flash app with #.

An example url


When I use the url helper to get the segments Codeigniter ignores everything after the #. Any idea how I can read these segments?

Many thanks.

The # is a reserved symbol in a URI scheme: http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax

If you want to use it, you will have to escape it, to "#" instead of "#".

So is it possible to grab the segments using $this->uri->segment(n) when using this type of url mysite/#/segment/segment/segment/ ?


No, the '#' is reserved in a URI.

Ah, wait. Stupid forum software is ff-ing up my post.

Maybe as code:
your URI should be mysite/#/segment/segment/segment

Arrghhh... That doesn't work either. Replace the '#' with a procent sign, followed by the number 23.

Swfaddress] utilises # to communicate between swf's, javascript to set the url and title of a web page. I understand that # is used for deep linking within the html page and that it is reserved for this purpose.

Is it not possible to get CI to someway use $this->uri->segment(n) if the url includes #.

The short answer is no, the URL is parsed by the webserver before it reaches your application.

Having said that, there are some things I can think of:
- use something that is not reserved by standards, and stick to an RFC standard URI.
- dump $_SERVER, and see if there's a variable that contains what you want (means you have to parse it yourself).
- use a rewrite rule to rewrite /#/ to for example /~/, which will get to CI as a segment.

Hi WanWizard,

Thanks for your input so far, it is very much appreciated.

I am gonna junk the use of php codeigniter for reading the url and use JS instead. Do you know why you can grab the URL with JS using document.location but it is not possible to do something similar with PHP when using # as a segment?


Because the # in the URL has meaning client-side, but not server side.

The browser already strips the anchor bit when it sends the HTTP request to the server, so the server will never see it. You can test this by adding an anchor (#somthing) to any URL in the browsers URL bar, and press enter. The browser won't request the page, as it is already loaded.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.